]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
resolve: first increment the reference counter
authorYu Watanabe <watanabe.yu+github@gmail.com>
Fri, 6 May 2022 12:32:37 +0000 (21:32 +0900)
committerYu Watanabe <watanabe.yu+github@gmail.com>
Sat, 7 May 2022 06:14:41 +0000 (15:14 +0900)
When `exist->rr` and `rr` point to the same object, then it may be freed by
the `dns_resource_record_unref()`.

src/resolve/resolved-dns-answer.c

index 479af69d0fce7a0f54f3006d5609fa7b31e343f6..bbc1bdeecdac59f8954e2872a14aba94d7f3005a 100644 (file)
@@ -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) {