Skip to content

Commit 73bfd7b

Browse files
committed
resolve: fix potential memleak and use-after-free
When stub stream is closed early, then queries associated to the stream are freed. Previously, the timer event source for queries may not be disabled, hence may be triggered with already freed query. See also dns_stub_stream_complete(). Note that we usually not set NULL or zero when freeing simple objects. But, here DnsQuery is large and complicated object, and the element may be referenced in subsequent freeing process in the future. Hence, for safety, let's set NULL to the pointer.
1 parent ec82f86 commit 73bfd7b

File tree

1 file changed

+2
-0
lines changed

1 file changed

+2
-0
lines changed

src/resolve/resolved-dns-query.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -381,6 +381,8 @@ DnsQuery *dns_query_free(DnsQuery *q) {
381381
if (!q)
382382
return NULL;
383383

384+
q->timeout_event_source = sd_event_source_disable_unref(q->timeout_event_source);
385+
384386
while (q->auxiliary_queries)
385387
dns_query_free(q->auxiliary_queries);
386388

0 commit comments

Comments
 (0)