From c7747008dd6fc9efab89ddf104772914b26deddc Mon Sep 17 00:00:00 2001 From: Tom Schuring Date: Wed, 6 May 2026 10:02:07 +0000 Subject: [PATCH] Fix connection leak in gst-client interactive mode In gstd_client_cmd_socket the GSocketConnection allocated by g_socket_client_connect_to_host was only closed and unrefed on the read/write error paths. The success path fell through to 'out:' without closing, leaking one fd and one GObject per command. On the gstd side this is more impactful than a typical client leak: the threaded socket service holds a worker thread per open connection (g_threaded_socket_service_new in gstd_tcp.c). After N successful commands from an interactive gst-client session against gstd started with --tcp-max-threads N, all worker slots are pinned on idle leaked connections and subsequent connections queue indefinitely. Fold the close+unref into the unified 'out:' label so success and error paths share a single cleanup, and guard with a NULL check so the early-return path where g_socket_client_connect_to_host returns NULL stays safe. --- gst_client/gst_client.c | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/gst_client/gst_client.c b/gst_client/gst_client.c index 6bf9699f..67494535 100644 --- a/gst_client/gst_client.c +++ b/gst_client/gst_client.c @@ -653,11 +653,12 @@ gstd_client_cmd_socket (gchar * name, gchar * arg, GstdClientData * data) g_string_free (response, TRUE); write_error: - g_io_stream_close (G_IO_STREAM (data->con), NULL, NULL); - g_object_unref (data->con); - data->con = NULL; - out: + if (data->con) { + g_io_stream_close (G_IO_STREAM (data->con), NULL, NULL); + g_object_unref (data->con); + data->con = NULL; + } return ret; }