]> source.dussan.org Git - rspamd.git/commitdiff
Avoid descriptors leak in lua_http.
authorVsevolod Stakhov <vsevolod@highsecure.ru>
Wed, 3 Dec 2014 12:37:48 +0000 (12:37 +0000)
committerVsevolod Stakhov <vsevolod@highsecure.ru>
Wed, 3 Dec 2014 12:37:48 +0000 (12:37 +0000)
src/lua/lua_http.c

index 12b0072d37fccf56db3697f9e5eb949457016c37..1d5e3bcf89c7e820cbdf69b6c97207fcef15eeee 100644 (file)
@@ -45,6 +45,7 @@ struct lua_http_cbdata {
        struct event_base *ev_base;
        struct timeval tv;
        rspamd_inet_addr_t addr;
+       gint fd;
        gint cbref;
 };
 
@@ -77,6 +78,10 @@ lua_http_fin (gpointer arg)
                rspamd_http_message_free (cbd->msg);
        }
 
+       if (cbd->fd != -1) {
+               close (cbd->fd);
+       }
+
        g_slice_free1 (sizeof (struct lua_http_cbdata), cbd);
 }
 
@@ -151,6 +156,7 @@ lua_http_make_connection (struct lua_http_cbdata *cbd)
                msg_info ("cannot connect to %v", cbd->msg->host);
                return FALSE;
        }
+       cbd->fd = fd;
        cbd->conn = rspamd_http_connection_new (NULL, lua_http_error_handler,
                        lua_http_finish_handler, RSPAMD_HTTP_CLIENT_SIMPLE, RSPAMD_HTTP_CLIENT);
 
@@ -333,6 +339,7 @@ lua_http_request (lua_State *L)
        cbd->msg = msg;
        cbd->ev_base = ev_base;
        msec_to_tv (timeout, &cbd->tv);
+       cbd->fd = -1;
        if (session) {
                cbd->session = session;
                register_async_event (session,