[Spice-devel] [spice-server v5 2/5] reds: Close sockets when using spice_server_destroy()

Christophe Fergeau cfergeau at redhat.com
Tue Feb 28 12:21:53 UTC 2017


Currently, the network sockets opened by reds_init_net() are not closed
on destruction, in other words they are leaked.

Signed-off-by: Christophe Fergeau <cfergeau at redhat.com>
Acked-by: Pavel Grunt <pgrunt at redhat.com>
---
 server/reds.c | 15 +++++++++++++--
 1 file changed, 13 insertions(+), 2 deletions(-)

diff --git a/server/reds.c b/server/reds.c
index 39a7a31..b01e037 100644
--- a/server/reds.c
+++ b/server/reds.c
@@ -3390,8 +3390,6 @@ static int do_spice_init(RedsState *reds, SpiceCoreInterface *core_interface)
     }
     reds->core = core_interface_adapter;
     reds->core.public_interface = core_interface;
-    reds->listen_socket = -1;
-    reds->secure_listen_socket = -1;
     reds->agent_dev = red_char_device_vdi_port_new(reds);
     reds_update_agent_properties(reds);
     reds->clients = NULL;
@@ -3484,6 +3482,9 @@ SPICE_GNUC_VISIBLE SpiceServer *spice_server_new(void)
 #ifdef RED_STATISTICS
     reds->stat_file = stat_file_new(REDS_MAX_STAT_NODES);
 #endif
+    reds->listen_socket = -1;
+    reds->secure_listen_socket = -1;
+
     return reds;
 }
 
@@ -3663,6 +3664,16 @@ SPICE_GNUC_VISIBLE void spice_server_destroy(SpiceServer *reds)
     if (reds->main_dispatcher) {
         g_object_unref(reds->main_dispatcher);
     }
+    if (reds->listen_socket != -1) {
+       reds_core_watch_remove(reds, reds->listen_watch);
+       if (reds->config->spice_listen_socket_fd != reds->listen_socket) {
+          close(reds->listen_socket);
+       }
+    }
+    if (reds->secure_listen_socket != -1) {
+       reds_core_watch_remove(reds, reds->secure_listen_watch);
+       close(reds->secure_listen_socket);
+    }
 
     reds_cleanup(reds);
 #ifdef RED_STATISTICS
-- 
2.9.3



More information about the Spice-devel mailing list