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

Christophe Fergeau cfergeau at redhat.com
Mon Feb 6 17:15:53 UTC 2017


Currently, the network sockets opened by reds_init_net() are not closed
on destruction, in other words they are leaked.
---
 server/reds.c | 13 +++++++++++++
 1 file changed, 13 insertions(+)

diff --git a/server/reds.c b/server/reds.c
index 953a95a..ff0f0e2 100644
--- a/server/reds.c
+++ b/server/reds.c
@@ -3472,6 +3472,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;
 }
 
@@ -3651,6 +3654,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