From nobody Tue Feb 10 05:43:59 2026 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 216.205.24.124 as permitted sender) client-ip=216.205.24.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 216.205.24.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=1632719296; cv=none; d=zohomail.com; s=zohoarc; b=ltck80EZPCZjVDPjMOqj1+SlQJSCtLziHFxzdNG2c4OcuElgvi4bFzEsrVHj7Nn2J+x0+QI1P4zS8DHdUKDz8YqTQDm/He+vWeAwz0brNQccHN1BbFlPDjEQc6xINKtVNQn9HqvuNd6b6dpJnhtWrsd0fNxw6ap7Pvaow2wq/5Y= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1632719296; 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=u1BQAwDRK6f1k2HChW0SzixIYwSNLYOzRZMiWpKhMTs=; b=Ciwd20KAVQ+rmJ6vvCsiPSSfEDuH92UwuSxuP6wrX/iO6wAx2S8TvZoTBR0VkZ/qposPay/6aNyOH9xvB5tzlG9oBruk4DPgL73xOTGJaTKjVUlYPukPAttcZnSUaMoDe1uEBMA9yyOl9sBZEC8Ms6bJCDgl4QytbaeeAE2vpoY= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 216.205.24.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 [216.205.24.124]) by mx.zohomail.com with SMTPS id 1632719296885328.6919190148111; Sun, 26 Sep 2021 22:08:16 -0700 (PDT) Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-143-dtZu3ghHPx6CzRcHbrNqUQ-1; Mon, 27 Sep 2021 01:08:14 -0400 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id C4235802936; Mon, 27 Sep 2021 05:08:08 +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 A5B566B55B; Mon, 27 Sep 2021 05:08:08 +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 72A844EA38; Mon, 27 Sep 2021 05:08:08 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id 18R581Yo004196 for ; Mon, 27 Sep 2021 01:08:01 -0400 Received: by smtp.corp.redhat.com (Postfix) id AE964179B3; Mon, 27 Sep 2021 05:08:01 +0000 (UTC) Received: from localhost.localdomain (unknown [10.40.192.53]) by smtp.corp.redhat.com (Postfix) with ESMTP id E726C60657 for ; Mon, 27 Sep 2021 05:08:00 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1632719295; 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=u1BQAwDRK6f1k2HChW0SzixIYwSNLYOzRZMiWpKhMTs=; b=U4h9NUl+VdX1KrzuczsVzz1F1mv8zfUJ8tFp0EunoRg9EBO6YPmaofgiuh+iyJr9iQpm8H B+c7Aa4woX9cchZ0Epg4wrb7gbP9NwwjIAtogHj1eA3zCM7G+0G5X9pvysyi7ogl9IBY4s MUgoD1c4C/PuHXtX2FxsLjMtnkj4jLM= X-MC-Unique: dtZu3ghHPx6CzRcHbrNqUQ-1 From: Michal Privoznik To: libvir-list@redhat.com Subject: [PATCH 3/8] virsh: Add wrapper for virStoragePoolFree Date: Mon, 27 Sep 2021 07:07:45 +0200 Message-Id: <90fcdd0eb1f2bdd2d2dd1e39ae7092969c1fe378.1632718996.git.mprivozn@redhat.com> In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.11 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.79 on 10.5.11.15 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: 1632719298291100001 Content-Type: text/plain; charset="utf-8" Similarly to virshDomainFree add a wrapper for the snapshot object freeing function. Signed-off-by: Michal Privoznik --- build-aux/syntax-check.mk | 2 +- tools/virsh-completer-pool.c | 3 +- tools/virsh-completer-volume.c | 4 +- tools/virsh-domain.c | 3 +- tools/virsh-pool.c | 67 +++++++++++----------------------- tools/virsh-util.c | 11 ++++++ tools/virsh-util.h | 5 +++ tools/virsh-volume.c | 29 ++++----------- 8 files changed, 51 insertions(+), 73 deletions(-) diff --git a/build-aux/syntax-check.mk b/build-aux/syntax-check.mk index 84cb895d86..111d2109e8 100644 --- a/build-aux/syntax-check.mk +++ b/build-aux/syntax-check.mk @@ -868,7 +868,7 @@ sc_gettext_init: $(_sc_search_regexp) =20 sc_prohibit_obj_free_apis_in_virsh: - @prohibit=3D'\bvir(Domain|DomainSnapshot|Interface|Secret)Free\b' \ + @prohibit=3D'\bvir(Domain|DomainSnapshot|Interface|Secret|StoragePool)Fre= e\b' \ in_vc_files=3D'virsh.*\.[ch]$$' \ exclude=3D'sc_prohibit_obj_free_apis_in_virsh' \ halt=3D'avoid using public virXXXFree in virsh, use virsh-prefixed wrappe= rs instead' \ diff --git a/tools/virsh-completer-pool.c b/tools/virsh-completer-pool.c index 9350eff2d3..84e9d6cc5a 100644 --- a/tools/virsh-completer-pool.c +++ b/tools/virsh-completer-pool.c @@ -21,6 +21,7 @@ #include =20 #include "virsh-completer-pool.h" +#include "virsh-util.h" #include "conf/storage_conf.h" #include "viralloc.h" #include "virsh-pool.h" @@ -61,7 +62,7 @@ virshStoragePoolNameCompleter(vshControl *ctl, ret =3D g_steal_pointer(&tmp); =20 for (i =3D 0; i < npools; i++) - virStoragePoolFree(pools[i]); + virshStoragePoolFree(pools[i]); g_free(pools); return ret; } diff --git a/tools/virsh-completer-volume.c b/tools/virsh-completer-volume.c index fcbc28b13b..1d83643c69 100644 --- a/tools/virsh-completer-volume.c +++ b/tools/virsh-completer-volume.c @@ -21,6 +21,7 @@ #include =20 #include "virsh-completer-volume.h" +#include "virsh-util.h" #include "viralloc.h" #include "virsh-pool.h" #include "virsh.h" @@ -32,7 +33,7 @@ virshStorageVolNameCompleter(vshControl *ctl, unsigned int flags) { virshControl *priv =3D ctl->privData; - virStoragePoolPtr pool =3D NULL; + g_autoptr(virshStoragePool) pool =3D NULL; virStorageVolPtr *vols =3D NULL; int rc; int nvols =3D 0; @@ -63,7 +64,6 @@ virshStorageVolNameCompleter(vshControl *ctl, ret =3D g_steal_pointer(&tmp); =20 cleanup: - virStoragePoolFree(pool); for (i =3D 0; i < nvols; i++) virStorageVolFree(vols[i]); g_free(vols); diff --git a/tools/virsh-domain.c b/tools/virsh-domain.c index 0b78fbf728..461a5e19f6 100644 --- a/tools/virsh-domain.c +++ b/tools/virsh-domain.c @@ -3801,7 +3801,7 @@ cmdUndefine(vshControl *ctl, const vshCmd *cmd) } =20 if (pool) { - virStoragePoolPtr storagepool =3D NULL; + g_autoptr(virshStoragePool) storagepool =3D NULL; =20 if (!source) { vshError(ctl, @@ -3820,7 +3820,6 @@ cmdUndefine(vshControl *ctl, const vshCmd *cmd) } =20 vol.vol =3D virStorageVolLookupByName(storagepool, source); - virStoragePoolFree(storagepool); =20 } else { vol.vol =3D virStorageVolLookupByPath(priv->conn, source); diff --git a/tools/virsh-pool.c b/tools/virsh-pool.c index fd9d5ead63..d391257f6e 100644 --- a/tools/virsh-pool.c +++ b/tools/virsh-pool.c @@ -20,6 +20,7 @@ =20 #include #include "virsh-pool.h" +#include "virsh-util.h" =20 #include "internal.h" #include "virbuffer.h" @@ -219,7 +220,7 @@ static const vshCmdOptDef opts_pool_autostart[] =3D { static bool cmdPoolAutostart(vshControl *ctl, const vshCmd *cmd) { - virStoragePoolPtr pool; + g_autoptr(virshStoragePool) pool =3D NULL; const char *name; int autostart; =20 @@ -233,7 +234,6 @@ cmdPoolAutostart(vshControl *ctl, const vshCmd *cmd) vshError(ctl, _("failed to mark pool %s as autostarted"), name= ); else vshError(ctl, _("failed to unmark pool %s as autostarted"), na= me); - virStoragePoolFree(pool); return false; } =20 @@ -242,7 +242,6 @@ cmdPoolAutostart(vshControl *ctl, const vshCmd *cmd) else vshPrintExtra(ctl, _("Pool %s unmarked as autostarted\n"), name); =20 - virStoragePoolFree(pool); return true; } =20 @@ -271,7 +270,7 @@ static const vshCmdOptDef opts_pool_create[] =3D { static bool cmdPoolCreate(vshControl *ctl, const vshCmd *cmd) { - virStoragePoolPtr pool; + g_autoptr(virshStoragePool) pool =3D NULL; const char *from =3D NULL; g_autofree char *buffer =3D NULL; bool build; @@ -307,7 +306,6 @@ cmdPoolCreate(vshControl *ctl, const vshCmd *cmd) =20 vshPrintExtra(ctl, _("Pool %s created from %s\n"), virStoragePoolGetName(pool), from); - virStoragePoolFree(pool); return true; } =20 @@ -462,7 +460,7 @@ static const vshCmdOptDef opts_pool_create_as[] =3D { static bool cmdPoolCreateAs(vshControl *ctl, const vshCmd *cmd) { - virStoragePoolPtr pool; + g_autoptr(virshStoragePool) pool =3D NULL; const char *name; g_autofree char *xml =3D NULL; bool printXML =3D vshCommandOptBool(cmd, "print-xml"); @@ -500,7 +498,6 @@ cmdPoolCreateAs(vshControl *ctl, const vshCmd *cmd) } =20 vshPrintExtra(ctl, _("Pool %s created\n"), name); - virStoragePoolFree(pool); return true; } =20 @@ -530,7 +527,7 @@ static const vshCmdOptDef opts_pool_define[] =3D { static bool cmdPoolDefine(vshControl *ctl, const vshCmd *cmd) { - virStoragePoolPtr pool; + g_autoptr(virshStoragePool) pool =3D NULL; const char *from =3D NULL; g_autofree char *buffer =3D NULL; unsigned int flags =3D 0; @@ -552,7 +549,6 @@ cmdPoolDefine(vshControl *ctl, const vshCmd *cmd) =20 vshPrintExtra(ctl, _("Pool %s defined from %s\n"), virStoragePoolGetName(pool), from); - virStoragePoolFree(pool); return true; } =20 @@ -572,7 +568,7 @@ static const vshCmdInfo info_pool_define_as[] =3D { static bool cmdPoolDefineAs(vshControl *ctl, const vshCmd *cmd) { - virStoragePoolPtr pool; + g_autoptr(virshStoragePool) pool =3D NULL; const char *name; g_autofree char *xml =3D NULL; bool printXML =3D vshCommandOptBool(cmd, "print-xml"); @@ -592,7 +588,6 @@ cmdPoolDefineAs(vshControl *ctl, const vshCmd *cmd) } =20 vshPrintExtra(ctl, _("Pool %s defined\n"), name); - virStoragePoolFree(pool); return true; } =20 @@ -620,7 +615,7 @@ static const vshCmdOptDef opts_pool_build[] =3D { static bool cmdPoolBuild(vshControl *ctl, const vshCmd *cmd) { - virStoragePoolPtr pool; + g_autoptr(virshStoragePool) pool =3D NULL; bool ret =3D true; const char *name; unsigned int flags =3D 0; @@ -641,8 +636,6 @@ cmdPoolBuild(vshControl *ctl, const vshCmd *cmd) ret =3D false; } =20 - virStoragePoolFree(pool); - return ret; } =20 @@ -668,7 +661,7 @@ static const vshCmdOptDef opts_pool_destroy[] =3D { static bool cmdPoolDestroy(vshControl *ctl, const vshCmd *cmd) { - virStoragePoolPtr pool; + g_autoptr(virshStoragePool) pool =3D NULL; bool ret =3D true; const char *name; =20 @@ -682,7 +675,6 @@ cmdPoolDestroy(vshControl *ctl, const vshCmd *cmd) ret =3D false; } =20 - virStoragePoolFree(pool); return ret; } =20 @@ -708,7 +700,7 @@ static const vshCmdOptDef opts_pool_delete[] =3D { static bool cmdPoolDelete(vshControl *ctl, const vshCmd *cmd) { - virStoragePoolPtr pool; + g_autoptr(virshStoragePool) pool =3D NULL; bool ret =3D true; const char *name; =20 @@ -722,7 +714,6 @@ cmdPoolDelete(vshControl *ctl, const vshCmd *cmd) ret =3D false; } =20 - virStoragePoolFree(pool); return ret; } =20 @@ -748,7 +739,7 @@ static const vshCmdOptDef opts_pool_refresh[] =3D { static bool cmdPoolRefresh(vshControl *ctl, const vshCmd *cmd) { - virStoragePoolPtr pool; + g_autoptr(virshStoragePool) pool =3D NULL; bool ret =3D true; const char *name; =20 @@ -761,7 +752,6 @@ cmdPoolRefresh(vshControl *ctl, const vshCmd *cmd) vshError(ctl, _("Failed to refresh pool %s"), name); ret =3D false; } - virStoragePoolFree(pool); =20 return ret; } @@ -792,7 +782,7 @@ static const vshCmdOptDef opts_pool_dumpxml[] =3D { static bool cmdPoolDumpXML(vshControl *ctl, const vshCmd *cmd) { - virStoragePoolPtr pool; + g_autoptr(virshStoragePool) pool =3D NULL; bool ret =3D true; bool inactive =3D vshCommandOptBool(cmd, "inactive"); unsigned int flags =3D 0; @@ -811,7 +801,6 @@ cmdPoolDumpXML(vshControl *ctl, const vshCmd *cmd) ret =3D false; } =20 - virStoragePoolFree(pool); return ret; } =20 @@ -837,8 +826,7 @@ void virshStoragePoolListFree(struct virshStoragePoolLi= st *list) =20 if (list && list->pools) { for (i =3D 0; i < list->npools; i++) { - if (list->pools[i]) - virStoragePoolFree(list->pools[i]); + virshStoragePoolFree(list->pools[i]); } g_free(list->pools); } @@ -1003,8 +991,7 @@ virshStoragePoolListCollect(vshControl *ctl, =20 remove_entry: /* the pool has to be removed as it failed one of the filters */ - virStoragePoolFree(list->pools[i]); - list->pools[i] =3D NULL; + g_clear_pointer(&list->pools[i], virshStoragePoolFree); deleted++; } =20 @@ -1570,7 +1557,7 @@ static bool cmdPoolInfo(vshControl *ctl, const vshCmd *cmd) { virStoragePoolInfo info; - virStoragePoolPtr pool; + g_autoptr(virshStoragePool) pool =3D NULL; int autostart =3D 0; bool ret =3D true; bool bytes =3D false; @@ -1630,7 +1617,6 @@ cmdPoolInfo(vshControl *ctl, const vshCmd *cmd) ret =3D false; } =20 - virStoragePoolFree(pool); return ret; } =20 @@ -1656,13 +1642,12 @@ static const vshCmdOptDef opts_pool_name[] =3D { static bool cmdPoolName(vshControl *ctl, const vshCmd *cmd) { - virStoragePoolPtr pool; + g_autoptr(virshStoragePool) pool =3D NULL; =20 if (!(pool =3D virshCommandOptPoolBy(ctl, cmd, "pool", NULL, VIRSH_BYU= UID))) return false; =20 vshPrint(ctl, "%s\n", virStoragePoolGetName(pool)); - virStoragePoolFree(pool); return true; } =20 @@ -1691,7 +1676,7 @@ static const vshCmdOptDef opts_pool_start[] =3D { static bool cmdPoolStart(vshControl *ctl, const vshCmd *cmd) { - virStoragePoolPtr pool; + g_autoptr(virshStoragePool) pool =3D NULL; bool ret =3D true; const char *name =3D NULL; bool build; @@ -1723,7 +1708,6 @@ cmdPoolStart(vshControl *ctl, const vshCmd *cmd) ret =3D false; } =20 - virStoragePoolFree(pool); return ret; } =20 @@ -1749,7 +1733,7 @@ static const vshCmdOptDef opts_pool_undefine[] =3D { static bool cmdPoolUndefine(vshControl *ctl, const vshCmd *cmd) { - virStoragePoolPtr pool; + g_autoptr(virshStoragePool) pool =3D NULL; bool ret =3D true; const char *name; =20 @@ -1763,7 +1747,6 @@ cmdPoolUndefine(vshControl *ctl, const vshCmd *cmd) ret =3D false; } =20 - virStoragePoolFree(pool); return ret; } =20 @@ -1789,7 +1772,7 @@ static const vshCmdOptDef opts_pool_uuid[] =3D { static bool cmdPoolUuid(vshControl *ctl, const vshCmd *cmd) { - virStoragePoolPtr pool; + g_autoptr(virshStoragePool) pool =3D NULL; char uuid[VIR_UUID_STRING_BUFLEN]; =20 if (!(pool =3D virshCommandOptPoolBy(ctl, cmd, "pool", NULL, VIRSH_BYN= AME))) @@ -1800,7 +1783,6 @@ cmdPoolUuid(vshControl *ctl, const vshCmd *cmd) else vshError(ctl, "%s", _("failed to get pool UUID")); =20 - virStoragePoolFree(pool); return true; } =20 @@ -1827,8 +1809,8 @@ static bool cmdPoolEdit(vshControl *ctl, const vshCmd *cmd) { bool ret =3D false; - virStoragePoolPtr pool =3D NULL; - virStoragePoolPtr pool_edited =3D NULL; + g_autoptr(virshStoragePool) pool =3D NULL; + g_autoptr(virshStoragePool) pool_edited =3D NULL; unsigned int flags =3D VIR_STORAGE_XML_INACTIVE; g_autofree char *tmp_desc =3D NULL; virshControl *priv =3D ctl->privData; @@ -1865,11 +1847,6 @@ cmdPoolEdit(vshControl *ctl, const vshCmd *cmd) ret =3D true; =20 cleanup: - if (pool) - virStoragePoolFree(pool); - if (pool_edited) - virStoragePoolFree(pool_edited); - return ret; } =20 @@ -2018,7 +1995,7 @@ static const vshCmdOptDef opts_pool_event[] =3D { static bool cmdPoolEvent(vshControl *ctl, const vshCmd *cmd) { - virStoragePoolPtr pool =3D NULL; + g_autoptr(virshStoragePool) pool =3D NULL; bool ret =3D false; int eventId =3D -1; int timeout =3D 0; @@ -2088,8 +2065,6 @@ cmdPoolEvent(vshControl *ctl, const vshCmd *cmd) if (eventId >=3D 0 && virConnectStoragePoolEventDeregisterAny(priv->conn, eventId) < 0) ret =3D false; - if (pool) - virStoragePoolFree(pool); return ret; } =20 diff --git a/tools/virsh-util.c b/tools/virsh-util.c index 82523f2575..d537501387 100644 --- a/tools/virsh-util.c +++ b/tools/virsh-util.c @@ -307,6 +307,17 @@ virshSecretFree(virSecretPtr secret) } =20 =20 +void +virshStoragePoolFree(virStoragePoolPtr pool) +{ + if (!pool) + return; + + vshSaveLibvirtHelperError(); + virStoragePoolFree(pool); /* sc_prohibit_obj_free_apis_in_virsh */ +} + + int virshDomainGetXMLFromDom(vshControl *ctl, virDomainPtr dom, diff --git a/tools/virsh-util.h b/tools/virsh-util.h index 7165755550..3ff6f16784 100644 --- a/tools/virsh-util.h +++ b/tools/virsh-util.h @@ -64,6 +64,11 @@ void virshSecretFree(virSecretPtr secret); G_DEFINE_AUTOPTR_CLEANUP_FUNC(virshSecret, virshSecretFree); =20 +typedef virStoragePool virshStoragePool; +void +virshStoragePoolFree(virStoragePoolPtr pool); +G_DEFINE_AUTOPTR_CLEANUP_FUNC(virshStoragePool, virshStoragePoolFree); + int virshDomainState(vshControl *ctl, virDomainPtr dom, diff --git a/tools/virsh-volume.c b/tools/virsh-volume.c index 38bb62a48f..6e8f7721a3 100644 --- a/tools/virsh-volume.c +++ b/tools/virsh-volume.c @@ -83,7 +83,7 @@ virshCommandOptVolBy(vshControl *ctl, const vshCmd *cmd, const char **name, unsigned int flags) { virStorageVolPtr vol =3D NULL; - virStoragePoolPtr pool =3D NULL; + g_autoptr(virshStoragePool) pool =3D NULL; const char *n =3D NULL, *p =3D NULL; virshControl *priv =3D ctl->privData; =20 @@ -102,7 +102,6 @@ virshCommandOptVolBy(vshControl *ctl, const vshCmd *cmd, =20 if (virStoragePoolIsActive(pool) !=3D 1) { vshError(ctl, _("pool '%s' is not active"), p); - virStoragePoolFree(pool); return NULL; } } @@ -145,7 +144,7 @@ virshCommandOptVolBy(vshControl *ctl, const vshCmd *cmd, /* If the pool was specified, then make sure that the returned * volume is from the given pool */ if (pool && vol) { - virStoragePoolPtr volpool =3D NULL; + g_autoptr(virshStoragePool) volpool =3D NULL; =20 if ((volpool =3D virStoragePoolLookupByVolume(vol))) { if (STRNEQ(virStoragePoolGetName(volpool), @@ -157,13 +156,9 @@ virshCommandOptVolBy(vshControl *ctl, const vshCmd *cm= d, virStorageVolFree(vol); vol =3D NULL; } - virStoragePoolFree(volpool); } } =20 - if (pool) - virStoragePoolFree(pool); - return vol; } =20 @@ -234,7 +229,7 @@ virshVolSize(const char *data, unsigned long long *val) static bool cmdVolCreateAs(vshControl *ctl, const vshCmd *cmd) { - virStoragePoolPtr pool; + g_autoptr(virshStoragePool) pool =3D NULL; virStorageVolPtr vol =3D NULL; g_autofree char *xml =3D NULL; bool printXML =3D vshCommandOptBool(cmd, "print-xml"); @@ -373,7 +368,6 @@ cmdVolCreateAs(vshControl *ctl, const vshCmd *cmd) cleanup: if (vol) virStorageVolFree(vol); - virStoragePoolFree(pool); return ret; } =20 @@ -403,7 +397,7 @@ static const vshCmdOptDef opts_vol_create[] =3D { static bool cmdVolCreate(vshControl *ctl, const vshCmd *cmd) { - virStoragePoolPtr pool; + g_autoptr(virshStoragePool) pool =3D NULL; virStorageVolPtr vol; const char *from =3D NULL; bool ret =3D false; @@ -434,7 +428,6 @@ cmdVolCreate(vshControl *ctl, const vshCmd *cmd) } =20 cleanup: - virStoragePoolFree(pool); return ret; } =20 @@ -474,7 +467,7 @@ static const vshCmdOptDef opts_vol_create_from[] =3D { static bool cmdVolCreateFrom(vshControl *ctl, const vshCmd *cmd) { - virStoragePoolPtr pool =3D NULL; + g_autoptr(virshStoragePool) pool =3D NULL; virStorageVolPtr newvol =3D NULL, inputvol =3D NULL; const char *from =3D NULL; bool ret =3D false; @@ -513,8 +506,6 @@ cmdVolCreateFrom(vshControl *ctl, const vshCmd *cmd) =20 ret =3D true; cleanup: - if (pool) - virStoragePoolFree(pool); if (inputvol) virStorageVolFree(inputvol); if (newvol) @@ -582,7 +573,7 @@ static const vshCmdOptDef opts_vol_clone[] =3D { static bool cmdVolClone(vshControl *ctl, const vshCmd *cmd) { - virStoragePoolPtr origpool =3D NULL; + g_autoptr(virshStoragePool) origpool =3D NULL; virStorageVolPtr origvol =3D NULL, newvol =3D NULL; const char *name =3D NULL; g_autofree char *origxml =3D NULL; @@ -637,8 +628,6 @@ cmdVolClone(vshControl *ctl, const vshCmd *cmd) virStorageVolFree(origvol); if (newvol) virStorageVolFree(newvol); - if (origpool) - virStoragePoolFree(origpool); return ret; } =20 @@ -1395,7 +1384,7 @@ static bool cmdVolList(vshControl *ctl, const vshCmd *cmd G_GNUC_UNUSED) { virStorageVolInfo volumeInfo; - virStoragePoolPtr pool; + g_autoptr(virshStoragePool) pool =3D NULL; const char *unit; double val; bool details =3D vshCommandOptBool(cmd, "details"); @@ -1521,7 +1510,6 @@ cmdVolList(vshControl *ctl, const vshCmd *cmd G_GNUC_= UNUSED) =20 /* Cleanup remaining memory */ VIR_FREE(volInfoTexts); - virStoragePoolFree(pool); virshStorageVolListFree(list); =20 /* Return the desired value */ @@ -1585,7 +1573,7 @@ static const vshCmdOptDef opts_vol_pool[] =3D { static bool cmdVolPool(vshControl *ctl, const vshCmd *cmd) { - virStoragePoolPtr pool; + g_autoptr(virshStoragePool) pool =3D NULL; virStorageVolPtr vol; char uuid[VIR_UUID_STRING_BUFLEN]; =20 @@ -1615,7 +1603,6 @@ cmdVolPool(vshControl *ctl, const vshCmd *cmd) =20 /* Cleanup */ virStorageVolFree(vol); - virStoragePoolFree(pool); return true; } =20 --=20 2.32.0