]> source.dussan.org Git - rspamd.git/commitdiff
[Fix] Fix sockets leak in the client
authorVsevolod Stakhov <vsevolod@highsecure.ru>
Thu, 7 May 2020 19:55:31 +0000 (20:55 +0100)
committerVsevolod Stakhov <vsevolod@highsecure.ru>
Thu, 7 May 2020 19:55:31 +0000 (20:55 +0100)
Issue: #3328

src/client/rspamdclient.c

index e8c0b959cebc95e7275b01d991b906ede6ef4975..e65a6935c4b7b0a90154f0ca16041d027ee191aa 100644 (file)
@@ -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);
        }