From 8dfc00bbb4df3bff774eecc806128d09579a7f80 Mon Sep 17 00:00:00 2001 From: Vsevolod Stakhov Date: Thu, 7 May 2020 20:55:31 +0100 Subject: [PATCH] [Fix] Fix sockets leak in the client Issue: #3328 --- src/client/rspamdclient.c | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/src/client/rspamdclient.c b/src/client/rspamdclient.c index e8c0b959c..e65a6935c 100644 --- a/src/client/rspamdclient.c +++ b/src/client/rspamdclient.c @@ -279,7 +279,15 @@ rspamd_client_init (struct rspamd_http_context *http_ctx, 0, fd); + if (!conn->http_conn) { + rspamd_client_destroy (conn); + return NULL; + } + + /* Pass socket ownership */ + rspamd_http_connection_own_socket (conn); conn->server_name = g_string_new (name); + if (port != 0) { rspamd_printf_gstring (conn->server_name, ":%d", (int)port); } @@ -474,7 +482,10 @@ void rspamd_client_destroy (struct rspamd_client_connection *conn) { if (conn != NULL) { - rspamd_http_connection_unref (conn->http_conn); + if (conn->http_conn) { + rspamd_http_connection_unref (conn->http_conn); + } + if (conn->req != NULL) { rspamd_client_request_free (conn->req); } @@ -482,9 +493,11 @@ rspamd_client_destroy (struct rspamd_client_connection *conn) if (conn->key) { rspamd_pubkey_unref (conn->key); } + if (conn->keypair) { rspamd_keypair_unref (conn->keypair); } + g_string_free (conn->server_name, TRUE); g_free (conn); } -- 2.39.5