From nobody Mon Feb 9 06:05:36 2026 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 170.10.129.124 as permitted sender) client-ip=170.10.129.124; envelope-from=libvir-list-bounces@redhat.com; helo=us-smtp-delivery-124.mimecast.com; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 170.10.129.124 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1638543668; cv=none; d=zohomail.com; s=zohoarc; b=ZIPqdpC6Qu/2QJIMds+biMPwrD63UxTjgouE0hsFyjt+M1hbY/zs1VrlGYEcQCWsb/tVGLQOPQoqTowQXKiLBIRLR1gtoiWTT5P+vLh4p2MrRo9J+a2Dk+Al6EvvsIqcgGtn1wY8GxBqvmx2e3cer/cxQopIcmV9/xmEdpBqwKY= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1638543668; h=Content-Type:Content-Transfer-Encoding:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=EIA4xmOL+tvIzyrNTFaqr7lZlefMSfOaKXSTxbPy/y4=; b=No96MNCKN4chg+BdXyunK2fUgmVlSoMl/BIa90EbBaesfpb7VhC/qqhful3Jku2x2f1mMm1vuYkgPhDUxASfM4npdz2up5Q6oc7LEFl//CeNmgwyi9j+KMLTXsAH5T/8RD4KMgTDVUOTi4o41BsDQhS5bcGIb6n5vg8bcwQG9zI= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 170.10.129.124 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by mx.zohomail.com with SMTPS id 1638543668815165.51395733793163; Fri, 3 Dec 2021 07:01:08 -0800 (PST) Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-477-3gSwM225PaqPnVHf2wF7yg-1; Fri, 03 Dec 2021 10:01:03 -0500 Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.phx2.redhat.com [10.5.11.23]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 4D7D664162; Fri, 3 Dec 2021 15:00:46 +0000 (UTC) Received: from colo-mx.corp.redhat.com (colo-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.21]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 3054F19D9F; Fri, 3 Dec 2021 15:00:46 +0000 (UTC) Received: from lists01.pubmisc.prod.ext.phx2.redhat.com (lists01.pubmisc.prod.ext.phx2.redhat.com [10.5.19.33]) by colo-mx.corp.redhat.com (Postfix) with ESMTP id F01614A7C9; Fri, 3 Dec 2021 15:00:45 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.phx2.redhat.com [10.5.11.22]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id 1B3Ew1HD029702 for ; Fri, 3 Dec 2021 09:58:01 -0500 Received: by smtp.corp.redhat.com (Postfix) id D077C10016FE; Fri, 3 Dec 2021 14:58:01 +0000 (UTC) Received: from speedmetal.lan (unknown [10.40.208.10]) by smtp.corp.redhat.com (Postfix) with ESMTP id 3844310016F4 for ; Fri, 3 Dec 2021 14:58:00 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1638543667; h=from:from:sender:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:list-id:list-help: list-unsubscribe:list-subscribe:list-post; bh=EIA4xmOL+tvIzyrNTFaqr7lZlefMSfOaKXSTxbPy/y4=; b=hD8KsQzx2UVjGB0pn605Syd53hRuq81ApAxjtE3m/FjMZzVrgNnbWShhGUil0UyDP1ZRKb tPprsBgi7HwNSUv4Jctg0GjDSr/kXYUcsrUWiru1sQeHJ43bGwLn446AfvtuPxyJnu67Uw pEaK8qjKP5UPNfGgi4FeuTIYLoHim+Y= X-MC-Unique: 3gSwM225PaqPnVHf2wF7yg-1 From: Peter Krempa To: libvir-list@redhat.com Subject: [PATCH 15/16] qemu: agent: Automatically free virJSONValue-s Date: Fri, 3 Dec 2021 15:57:42 +0100 Message-Id: In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.84 on 10.5.11.22 X-loop: libvir-list@redhat.com X-BeenThere: libvir-list@redhat.com X-Mailman-Version: 2.1.12 Precedence: junk List-Id: Development discussions about the libvirt library & tools List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: libvir-list-bounces@redhat.com Errors-To: libvir-list-bounces@redhat.com X-Scanned-By: MIMEDefang 2.84 on 10.5.11.23 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=libvir-list-bounces@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1638543670117100005 Content-Type: text/plain; charset="utf-8" Convert the code to use g_autoptr for the few cases sill using explicit cleanup. Signed-off-by: Peter Krempa --- src/qemu/qemu_agent.c | 60 ++++++++++++++----------------------------- 1 file changed, 19 insertions(+), 41 deletions(-) diff --git a/src/qemu/qemu_agent.c b/src/qemu/qemu_agent.c index c573e0fdf4..1eb31ffca2 100644 --- a/src/qemu/qemu_agent.c +++ b/src/qemu/qemu_agent.c @@ -1206,8 +1206,8 @@ int qemuAgentShutdown(qemuAgent *agent, qemuAgentShutdownMode mode) { int ret =3D -1; - virJSONValue *cmd; - virJSONValue *reply =3D NULL; + g_autoptr(virJSONValue) cmd =3D NULL; + g_autoptr(virJSONValue) reply =3D NULL; cmd =3D qemuAgentMakeCommand("guest-shutdown", "s:mode", qemuAgentShutdownModeTypeToString= (mode), @@ -1222,8 +1222,6 @@ int qemuAgentShutdown(qemuAgent *agent, ret =3D qemuAgentCommand(agent, cmd, &reply, VIR_DOMAIN_QEMU_AGENT_COMMAND_SHUTDOWN); - virJSONValueFree(cmd); - virJSONValueFree(reply); return ret; } @@ -1245,12 +1243,11 @@ int qemuAgentFSFreeze(qemuAgent *agent, const char = **mountpoints, unsigned int nmountpoints) { int ret =3D -1; - virJSONValue *cmd; - virJSONValue *arg =3D NULL; - virJSONValue *reply =3D NULL; + g_autoptr(virJSONValue) cmd =3D NULL; + g_autoptr(virJSONValue) reply =3D NULL; if (mountpoints && nmountpoints) { - arg =3D qemuAgentMakeStringsArray(mountpoints, nmountpoints); + g_autoptr(virJSONValue) arg =3D qemuAgentMakeStringsArray(mountpoi= nts, nmountpoints); if (!arg) return -1; @@ -1272,9 +1269,6 @@ int qemuAgentFSFreeze(qemuAgent *agent, const char **= mountpoints, } cleanup: - virJSONValueFree(arg); - virJSONValueFree(cmd); - virJSONValueFree(reply); return ret; } @@ -1292,10 +1286,8 @@ int qemuAgentFSFreeze(qemuAgent *agent, const char *= *mountpoints, int qemuAgentFSThaw(qemuAgent *agent) { int ret =3D -1; - virJSONValue *cmd; - virJSONValue *reply =3D NULL; - - cmd =3D qemuAgentMakeCommand("guest-fsfreeze-thaw", NULL); + g_autoptr(virJSONValue) cmd =3D qemuAgentMakeCommand("guest-fsfreeze-t= haw", NULL); + g_autoptr(virJSONValue) reply =3D NULL; if (!cmd) return -1; @@ -1309,8 +1301,6 @@ int qemuAgentFSThaw(qemuAgent *agent) } cleanup: - virJSONValueFree(cmd); - virJSONValueFree(reply); return ret; } @@ -1328,8 +1318,8 @@ qemuAgentSuspend(qemuAgent *agent, unsigned int target) { int ret =3D -1; - virJSONValue *cmd; - virJSONValue *reply =3D NULL; + g_autoptr(virJSONValue) cmd =3D NULL; + g_autoptr(virJSONValue) reply =3D NULL; cmd =3D qemuAgentMakeCommand(qemuAgentSuspendModeTypeToString(target), NULL); @@ -1339,8 +1329,6 @@ qemuAgentSuspend(qemuAgent *agent, agent->await_event =3D QEMU_AGENT_EVENT_SUSPEND; ret =3D qemuAgentCommand(agent, cmd, &reply, agent->timeout); - virJSONValueFree(cmd); - virJSONValueFree(reply); return ret; } @@ -1351,8 +1339,8 @@ qemuAgentArbitraryCommand(qemuAgent *agent, int timeout) { int ret =3D -1; - virJSONValue *cmd =3D NULL; - virJSONValue *reply =3D NULL; + g_autoptr(virJSONValue) cmd =3D NULL; + g_autoptr(virJSONValue) reply =3D NULL; *result =3D NULL; if (timeout < VIR_DOMAIN_QEMU_AGENT_COMMAND_MIN) { @@ -1374,8 +1362,6 @@ qemuAgentArbitraryCommand(qemuAgent *agent, cleanup: - virJSONValueFree(cmd); - virJSONValueFree(reply); return ret; } @@ -1384,8 +1370,8 @@ qemuAgentFSTrim(qemuAgent *agent, unsigned long long minimum) { int ret =3D -1; - virJSONValue *cmd; - virJSONValue *reply =3D NULL; + g_autoptr(virJSONValue) cmd =3D NULL; + g_autoptr(virJSONValue) reply =3D NULL; cmd =3D qemuAgentMakeCommand("guest-fstrim", "U:minimum", minimum, @@ -1395,8 +1381,6 @@ qemuAgentFSTrim(qemuAgent *agent, ret =3D qemuAgentCommand(agent, cmd, &reply, agent->timeout); - virJSONValueFree(cmd); - virJSONValueFree(reply); return ret; } @@ -1406,8 +1390,8 @@ qemuAgentGetVCPUs(qemuAgent *agent, { int ret =3D -1; size_t i; - virJSONValue *cmd; - virJSONValue *reply =3D NULL; + g_autoptr(virJSONValue) cmd =3D NULL; + g_autoptr(virJSONValue) reply =3D NULL; virJSONValue *data =3D NULL; size_t ndata; @@ -1461,8 +1445,6 @@ qemuAgentGetVCPUs(qemuAgent *agent, ret =3D ndata; cleanup: - virJSONValueFree(cmd); - virJSONValueFree(reply); return ret; } @@ -1696,8 +1678,8 @@ qemuAgentGetTime(qemuAgent *agent, { int ret =3D -1; unsigned long long json_time; - virJSONValue *cmd; - virJSONValue *reply =3D NULL; + g_autoptr(virJSONValue) cmd =3D NULL; + g_autoptr(virJSONValue) reply =3D NULL; cmd =3D qemuAgentMakeCommand("guest-get-time", NULL); @@ -1720,8 +1702,6 @@ qemuAgentGetTime(qemuAgent *agent, ret =3D 0; cleanup: - virJSONValueFree(cmd); - virJSONValueFree(reply); return ret; } @@ -1738,8 +1718,8 @@ qemuAgentSetTime(qemuAgent *agent, bool rtcSync) { int ret =3D -1; - virJSONValue *cmd; - virJSONValue *reply =3D NULL; + g_autoptr(virJSONValue) cmd =3D NULL; + g_autoptr(virJSONValue) reply =3D NULL; if (rtcSync) { cmd =3D qemuAgentMakeCommand("guest-set-time", NULL); @@ -1774,8 +1754,6 @@ qemuAgentSetTime(qemuAgent *agent, ret =3D 0; cleanup: - virJSONValueFree(cmd); - virJSONValueFree(reply); return ret; } --=20 2.31.1