[Spice-devel] [PATCH spice-server 01/10] tests: Check leaks in spice_server_add_ssl_client if invalid connection

Frediano Ziglio fziglio at redhat.com
Mon Sep 11 10:15:38 UTC 2017


Signed-off-by: Frediano Ziglio <fziglio at redhat.com>
---
 server/tests/Makefile.am  |  1 +
 server/tests/test-leaks.c | 12 ++++++++++++
 2 files changed, 13 insertions(+)

diff --git a/server/tests/Makefile.am b/server/tests/Makefile.am
index 01e636265..d50c590c3 100644
--- a/server/tests/Makefile.am
+++ b/server/tests/Makefile.am
@@ -138,6 +138,7 @@ test_vdagent_CPPFLAGS =			\
 test_codecs_parsing_CPPFLAGS = $(test_vdagent_CPPFLAGS)
 test_qxl_parsing_CPPFLAGS = $(test_vdagent_CPPFLAGS)
 test_fail_on_null_core_interface_CPPFLAGS = $(test_vdagent_CPPFLAGS)
+test_leaks_CPPFLAGS = $(test_vdagent_CPPFLAGS)
 
 if HAVE_GSTREAMER
 test_gst_SOURCES = test-gst.c \
diff --git a/server/tests/test-leaks.c b/server/tests/test-leaks.c
index 74ab2afd5..5be8ac859 100644
--- a/server/tests/test-leaks.c
+++ b/server/tests/test-leaks.c
@@ -29,6 +29,7 @@
  * For cleaner output you should suppress GLib checks with glib.supp file.
  */
 #include <config.h>
+#include <unistd.h>
 #include <spice.h>
 
 #include "test-glib-compat.h"
@@ -42,6 +43,7 @@ static void server_leaks(void)
     int result;
     SpiceCoreInterface *core;
     SpiceServer *server = spice_server_new();
+    int sv[2];
 
     g_assert_nonnull(server);
 
@@ -64,6 +66,16 @@ static void server_leaks(void)
     result = spice_server_set_channel_security(server, "main", SPICE_CHANNEL_SECURITY_SSL);
     g_assert_cmpint(result, ==, 0);
 
+    /* spice_server_add_ssl_client should not leak passing a disconnected socket */
+    g_test_expect_message(G_LOG_DOMAIN, G_LOG_LEVEL_WARNING,
+                          "*SSL_accept failed*");
+    g_assert_cmpint(socketpair(AF_LOCAL, SOCK_STREAM, 0, sv), ==, 0);
+    close(sv[1]);
+    result = spice_server_add_ssl_client(server, sv[0], 1);
+    g_assert_cmpint(result, ==, -1);
+    /* if the function fails should not close the socket */
+    g_assert_cmpint(close(sv[0]), ==, 0);
+
     spice_server_destroy(server);
     basic_event_loop_destroy();
 }
-- 
2.13.5



More information about the Spice-devel mailing list