From: Timo Sirainen Date: Sat, 19 Apr 2014 09:21:47 +0000 (+0200) Subject: lib-http: Fixed resource leaks in http_client_wait() occurring a dns_client is used. X-Git-Tag: 2.2.13.rc1~118 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=856ae2ad98cee79b2719911a3cc131d7f4ec8a90;p=thirdparty%2Fdovecot%2Fcore.git lib-http: Fixed resource leaks in http_client_wait() occurring a dns_client is used. If all DNS lookups finished before the end of the wait cycle, the dns_client would not be switched back to the original ioloop. --- diff --git a/src/lib-http/http-client-host.c b/src/lib-http/http-client-host.c index 2a16a6602c..89b07757b5 100644 --- a/src/lib-http/http-client-host.c +++ b/src/lib-http/http-client-host.c @@ -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); diff --git a/src/lib-http/http-client.c b/src/lib-http/http-client.c index 264427af7c..b4e1c0a427 100644 --- a/src/lib-http/http-client.c +++ b/src/lib-http/http-client.c @@ -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); } diff --git a/src/lib-http/test-http-client.c b/src/lib-http/test-http-client.c index 08aa851268..56004f460f 100644 --- a/src/lib-http/test-http-client.c +++ b/src/lib-http/test-http-client.c @@ -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(); }