commit 8dfc00b: [Fix] Fix sockets leak in the client

Vsevolod Stakhov vsevolod at highsecure.ru
Thu May 7 20:00:09 UTC 2020


Author: Vsevolod Stakhov
Date: 2020-05-07 20:55:31 +0100
URL: https://github.com/rspamd/rspamd/commit/8dfc00bbb4df3bff774eecc806128d09579a7f80

[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);
 	}


More information about the Commits mailing list