From: Yu Watanabe Date: Fri, 6 May 2022 12:32:37 +0000 (+0900) Subject: resolve: first increment the reference counter X-Git-Tag: v251-rc3~10^2~4 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=4ce30e4de05971ea93bc727695000d0025eb1591;p=thirdparty%2Fsystemd.git resolve: first increment the reference counter When `exist->rr` and `rr` point to the same object, then it may be freed by the `dns_resource_record_unref()`. --- diff --git a/src/resolve/resolved-dns-answer.c b/src/resolve/resolved-dns-answer.c index 479af69d0fc..bbc1bdeecda 100644 --- a/src/resolve/resolved-dns-answer.c +++ b/src/resolve/resolved-dns-answer.c @@ -169,8 +169,9 @@ int dns_answer_add( /* Entry already exists, keep the entry with the higher TTL. */ if (rr->ttl > exist->rr->ttl) { + dns_resource_record_ref(rr); dns_resource_record_unref(exist->rr); - exist->rr = dns_resource_record_ref(rr); /* lgtm [cpp/inconsistent-null-check] */ + exist->rr = rr; /* Update RRSIG and RR at the same time */ if (rrsig) {