]> git.ipfire.org Git - thirdparty/dovecot/core.git/commitdiff
lib-http: Fixed resource leaks in http_client_wait() occurring a dns_client is used.
authorTimo Sirainen <tss@iki.fi>
Sat, 19 Apr 2014 09:21:47 +0000 (11:21 +0200)
committerTimo Sirainen <tss@iki.fi>
Sat, 19 Apr 2014 09:21:47 +0000 (11:21 +0200)
If all DNS lookups finished before the end of the wait cycle, the dns_client would not be switched back to the original ioloop.

src/lib-http/http-client-host.c
src/lib-http/http-client.c
src/lib-http/test-http-client.c

index 2a16a6602c6114e3646292967e1204af475b9173..89b07757b5afbb6c5547f64f7ab850558379120b 100644 (file)
@@ -284,7 +284,7 @@ void http_client_host_switch_ioloop(struct http_client_host *host)
 {
        struct http_client_queue *const *queue_idx;
 
-       if (host->dns_lookup != NULL)
+       if (host->dns_lookup != NULL && host->client->set.dns_client == NULL)
                dns_lookup_switch_ioloop(host->dns_lookup);
        array_foreach(&host->queues, queue_idx)
                http_client_queue_switch_ioloop(*queue_idx);
index 264427af7c300108d56b214c69bbca18e3494280..b4e1c0a42700ff34898a41d6880daa643a4dd951 100644 (file)
@@ -204,6 +204,8 @@ void http_client_wait(struct http_client *client)
 
        client->ioloop = io_loop_create();
        http_client_switch_ioloop(client);
+       if (client->set.dns_client != NULL)
+               dns_client_switch_ioloop(client->set.dns_client);
        /* either we're waiting for network I/O or we're getting out of a
           callback using timeout_add_short(0) */
        i_assert(io_loop_have_ios(client->ioloop) ||
@@ -219,6 +221,8 @@ void http_client_wait(struct http_client *client)
 
        io_loop_set_current(prev_ioloop);
        http_client_switch_ioloop(client);
+       if (client->set.dns_client != NULL)
+               dns_client_switch_ioloop(client->set.dns_client);
        io_loop_set_current(client->ioloop);
        io_loop_destroy(&client->ioloop);
 }
index 08aa851268f41981ad1d7ac8e9c0dbb4130e064c..56004f460f727bfeb916cae6981f7be24db5409c 100644 (file)
@@ -6,6 +6,7 @@
 #include "write-full.h"
 #include "http-url.h"
 #include "http-client.h"
+#include "dns-lookup.h"
 
 struct http_test_request {
        struct io *io;
@@ -322,12 +323,30 @@ static void run_http_post(struct http_client *http_client, const char *url_str,
 
 int main(int argc, char *argv[])
 {
+       struct dns_client *dns_client;
+       struct dns_lookup_settings dns_set;
        struct http_client_settings http_set;
        struct http_client *http_client;
+       const char *error;
        struct ioloop *ioloop;
 
+       lib_init();
+
+       ioloop = io_loop_create();
+       io_loop_set_running(ioloop);
+
+
+       memset(&dns_set, 0, sizeof(dns_set));
+       dns_set.dns_client_socket_path = "/var/run/dovecot/dns-client";
+       dns_set.timeout_msecs = 30*1000;
+       dns_set.idle_timeout_msecs = UINT_MAX;
+       dns_client = dns_client_init(&dns_set);
+
+       if (dns_client_connect(dns_client, &error) < 0)
+               i_fatal("Couldn't initialize DNS client: %s", error);
+
        memset(&http_set, 0, sizeof(http_set));
-       http_set.dns_client_socket_path = "/var/run/dovecot/dns-client";
+       http_set.dns_client = dns_client;
        http_set.ssl_allow_invalid_cert = TRUE;
        http_set.ssl_ca_dir = "/etc/ssl/certs"; /* debian */
        http_set.ssl_ca_file = "/etc/pki/tls/cert.pem"; /* redhat */
@@ -339,11 +358,6 @@ int main(int argc, char *argv[])
        http_set.debug = TRUE;
        http_set.rawlog_dir = "/tmp/http-test";
 
-       lib_init();
-
-       ioloop = io_loop_create();
-       io_loop_set_running(ioloop);
-
        http_client = http_client_init(&http_set);
 
        switch (argc) {
@@ -363,6 +377,8 @@ int main(int argc, char *argv[])
        http_client_wait(http_client);
        http_client_deinit(&http_client);
 
+       dns_client_deinit(&dns_client);
+
        io_loop_destroy(&ioloop);
        lib_deinit();
 }