]> git.ipfire.org Git - thirdparty/dovecot/core.git/commitdiff
lib-dns: dns_lookup_abort() - If client isn't destroyed, delay freeing the lookup
authorTimo Sirainen <timo.sirainen@open-xchange.com>
Tue, 28 May 2024 23:03:35 +0000 (02:03 +0300)
committeraki.tuomi <aki.tuomi@open-xchange.com>
Tue, 4 Jun 2024 05:28:35 +0000 (05:28 +0000)
The lookup can't be removed from the linked list until its response has been
received, or the response could become matched against a wrong lookup.

src/lib-dns/dns-lookup.c

index 174718e87f62e424bc76a8e433b980c0d1433fdf..ce199d52dedaaf45c94647d6a84940db2d39f7fe 100644 (file)
@@ -78,7 +78,8 @@ static void dns_lookup_callback(struct dns_lookup *lookup)
                        lookup->result.msecs);
                i_assert(lookup->ptr_lookup || lookup->result.ips_count > 0);
        }
-       lookup->callback(&lookup->result, lookup->context);
+       if (lookup->callback != NULL)
+               lookup->callback(&lookup->result, lookup->context);
 }
 
 static void dns_lookup_callback_cached(struct dns_lookup *lookup)
@@ -257,9 +258,19 @@ static void dns_lookup_free(struct dns_lookup **_lookup)
        pool_unref(&lookup->pool);
 }
 
-void dns_lookup_abort(struct dns_lookup **lookup)
+void dns_lookup_abort(struct dns_lookup **_lookup)
 {
-       dns_lookup_free(lookup);
+       struct dns_lookup *lookup = *_lookup;
+       struct dns_client *client = lookup->client;
+
+       if (lookup == NULL)
+               return;
+       *_lookup = NULL;
+
+       if (client->deinit_client_at_free)
+               dns_client_deinit(&client);
+       else
+               lookup->callback = NULL;
 }
 
 static void dns_lookup_switch_ioloop_real(struct dns_lookup *lookup)