From: Timo Sirainen Date: Tue, 28 May 2024 23:03:35 +0000 (+0300) Subject: lib-dns: dns_lookup_abort() - If client isn't destroyed, delay freeing the lookup X-Git-Tag: 2.4.0~1622 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=f9e7f71e48dd4fe2b9af23796022fc256db3866d;p=thirdparty%2Fdovecot%2Fcore.git lib-dns: dns_lookup_abort() - If client isn't destroyed, delay freeing the lookup 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. --- diff --git a/src/lib-dns/dns-lookup.c b/src/lib-dns/dns-lookup.c index 174718e87f..ce199d52de 100644 --- a/src/lib-dns/dns-lookup.c +++ b/src/lib-dns/dns-lookup.c @@ -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)