From: Vsevolod Stakhov Date: Thu, 7 May 2020 19:55:31 +0000 (+0100) Subject: [Fix] Fix sockets leak in the client X-Git-Tag: 2.6~441 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=8dfc00bbb4df3bff774eecc806128d09579a7f80;p=rspamd.git [Fix] Fix sockets leak in the client Issue: #3328 --- 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); }