]> git.ipfire.org Git - thirdparty/dovecot/core.git/commitdiff
lib-dns: Always use dns_lookup_free
authorAki Tuomi <aki.tuomi@dovecot.fi>
Mon, 27 Aug 2018 11:16:46 +0000 (14:16 +0300)
committerVille Savolainen <ville.savolainen@dovecot.fi>
Tue, 13 Nov 2018 13:10:03 +0000 (15:10 +0200)
Ensures that all resources get free'd in single place,
Fixes memory leak and event double-unref.

Broken in 9ee82e3f660e6e072532283cad8668a578ac137d

src/lib-dns/dns-lookup.c

index 877488c9434d76f45780d2ea276e55db5aa7e387..31e2365bf3356c362035272afb410fbe7247508e 100644 (file)
@@ -86,7 +86,6 @@ static void dns_lookup_callback(struct dns_lookup *lookup)
                        lookup->result.msecs);
        }
        lookup->callback(&lookup->result, lookup->context);
-       event_unref(&lookup->event);
 }
 
 static void dns_client_disconnect(struct dns_client *client, const char *error)
@@ -207,11 +206,7 @@ int dns_lookup(const char *host, const struct dns_lookup_settings *set,
 
        client = dns_client_init(set);
        client->deinit_client_at_free = TRUE;
-       if (dns_client_lookup(client, host, callback, context, lookup_r) < 0) {
-               dns_client_deinit(&client);
-               return -1;
-       }
-       return 0;
+       return dns_client_lookup(client, host, callback, context, lookup_r);
 }
 
 int dns_lookup_ptr(const struct ip_addr *ip,
@@ -223,11 +218,7 @@ int dns_lookup_ptr(const struct ip_addr *ip,
 
        client = dns_client_init(set);
        client->deinit_client_at_free = TRUE;
-       if (dns_client_lookup_ptr(client, ip, callback, context, lookup_r) < 0) {
-               dns_client_deinit(&client);
-               return -1;
-       }
-       return 0;
+       return dns_client_lookup_ptr(client, ip, callback, context, lookup_r);
 }
 
 static void dns_client_idle_timeout(struct dns_client *client)
@@ -404,7 +395,7 @@ dns_client_lookup_common(struct dns_client *client,
                }
                if (ret <= 0) {
                        dns_lookup_callback(lookup);
-                       pool_unref(&lookup->pool);
+                       dns_lookup_free(&lookup);
                        return -1;
                }
        }