]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
resolvectl: fix JSON reply cleanup in varlink_dump_dns_configuration 42812/head
authordongshengyuan <545258830@qq.com>
Tue, 30 Jun 2026 09:13:10 +0000 (17:13 +0800)
committerdongshengyuan <545258830@qq.com>
Tue, 30 Jun 2026 09:26:41 +0000 (17:26 +0800)
varlink_call_and_log() does not hand out a new reference for the reply
object, so the caller should not unref it. The _cleanup_(sd_json_variant_unrefp)
on reply was therefore wrong from the start.

The original TAKE_PTR(reply) was working around this incorrect cleanup
by preventing it from firing, but that left reply's refcount one too
high after sd_json_variant_ref(v) incremented the parent's count.

Fix by dropping _cleanup_(sd_json_variant_unrefp) from the reply
variable declaration entirely, as suggested by Lennart Poettering.

Signed-off-by: dongshengyuan <dongshengyuan@uniontech.com>
src/resolve/resolvectl.c

index af7ed4367266dbcb81372eb40fdf6aa3d8bb352e..011162865b8f20bb11f5e4fe8d0139c8d73e976e 100644 (file)
@@ -1114,7 +1114,7 @@ static int verb_tlsa(int argc, char *argv[], uintptr_t _data, void *userdata) {
 
 static int varlink_dump_dns_configuration(sd_json_variant **ret) {
         _cleanup_(sd_varlink_unrefp) sd_varlink *vl = NULL;
-        _cleanup_(sd_json_variant_unrefp) sd_json_variant *reply = NULL;
+        sd_json_variant *reply = NULL;
         sd_json_variant *v;
         int r;
 
@@ -1133,7 +1133,6 @@ static int varlink_dump_dns_configuration(sd_json_variant **ret) {
         if (!sd_json_variant_is_array(v))
                 return log_error_errno(SYNTHETIC_ERRNO(ENODATA), "DumpDNSConfiguration() response missing 'configuration' key.");
 
-        TAKE_PTR(reply);
         *ret = sd_json_variant_ref(v);
         return 0;
 }