resolvectl: fix JSON reply cleanup in varlink_dump_dns_configuration

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>
This commit is contained in:
dongshengyuan
2026-06-30 17:26:41 +08:00
parent 04ab634776
commit 7808a0c541
+1 -2
View 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;
}