From nobody Sun May 19 10:57:28 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 170.10.133.124 as permitted sender) client-ip=170.10.133.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.133.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=1632719288; cv=none; d=zohomail.com; s=zohoarc; b=CUwcZZs1wLdB32MhtKqD1K0Oq8OTJ3PibfolBJQRRhaS3hacqxBrPmPXaCfQ1zBRmxE52nkx8tEOGJRKDxGaM0BrTRzGL4YOJo/rU3MTtc7fRlnSWQVogEAd4nSBup1Cc3ZTHGcBrkcdn0ze/9NMXUCkuRxgU6OQNsNa97qpZ8U= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1632719288; 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=YgrTFd6/fXfU+L+EDc8N4vqLJh07qFDZPkrsYUVLNIE=; b=jhxftGWe0Go/sAVQbGqv6qbQzv/Pj44t664pLT2i4l+VcvwaLeCH+Gox0uM2oAC3XFGvqsU6cL9hCdM7CqVVMo40rkht9xPtBTnf+Pf3Bkr04nz5TDO/zPJj/QDxED7LPkKVbsK0Hy8MT6r/i9TBRX+NCPxstZpqP6MxYyN0yk8= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 170.10.133.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.133.124]) by mx.zohomail.com with SMTPS id 1632719288114663.0072613693129; Sun, 26 Sep 2021 22:08:08 -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-100-f8Flp4CUNyutDiNzi4JIKA-1; Mon, 27 Sep 2021 01:08:05 -0400 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id DEFF7101F003; Mon, 27 Sep 2021 05:08:00 +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 9677E60C7F; Mon, 27 Sep 2021 05:08:00 +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 0042F4EA2F; Mon, 27 Sep 2021 05:07:59 +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 18R57x2i004184 for ; Mon, 27 Sep 2021 01:07:59 -0400 Received: by smtp.corp.redhat.com (Postfix) id 66A0B189C4; Mon, 27 Sep 2021 05:07:59 +0000 (UTC) Received: from localhost.localdomain (unknown [10.40.192.53]) by smtp.corp.redhat.com (Postfix) with ESMTP id CDC29179B3 for ; Mon, 27 Sep 2021 05:07:58 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1632719287; 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=YgrTFd6/fXfU+L+EDc8N4vqLJh07qFDZPkrsYUVLNIE=; b=EejBZ2VJ8oweiYP4eCjPKDVmQPeTsNAB5qloH0hK+azUE4qdHg7Q9CSI4GxFV8zM9+kL0o 5xL34D/Gq0dLWnO8btwRBSD3QP/zBuY2UK/miFemiUoNxtEBPr0Fnh+Vb1ZRcGBOQiTcCY G8LP/iPzKIrCX7c0OX7LCcDl2bLgi2I= X-MC-Unique: f8Flp4CUNyutDiNzi4JIKA-1 From: Michal Privoznik To: libvir-list@redhat.com Subject: [PATCH 1/8] virsh-util.h: Fix ordering of virshXXXFree functions Date: Mon, 27 Sep 2021 07:07:43 +0200 Message-Id: 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.12 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: 1632719289944100002 Content-Type: text/plain; charset="utf-8" Currently the order of virshXXXFree functions in the header file does not correspond to the order in the corresponding .c file. Signed-off-by: Michal Privoznik Acked-by: Jonathon Jongsma --- tools/virsh-util.h | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/tools/virsh-util.h b/tools/virsh-util.h index 6115b05d4d..f7e8116de3 100644 --- a/tools/virsh-util.h +++ b/tools/virsh-util.h @@ -40,16 +40,10 @@ virshCommandOptDomain(vshControl *ctl, const char **name); =20 typedef virDomain virshDomain; - void virshDomainFree(virDomainPtr dom); G_DEFINE_AUTOPTR_CLEANUP_FUNC(virshDomain, virshDomainFree); =20 -typedef virSecret virshSecret; -void -virshSecretFree(virSecretPtr secret); -G_DEFINE_AUTOPTR_CLEANUP_FUNC(virshSecret, virshSecretFree); - typedef virDomainCheckpoint virshDomainCheckpoint; void virshDomainCheckpointFree(virDomainCheckpointPtr chk); @@ -60,6 +54,11 @@ void virshDomainSnapshotFree(virDomainSnapshotPtr snap); G_DEFINE_AUTOPTR_CLEANUP_FUNC(virshDomainSnapshot, virshDomainSnapshotFree= ); =20 +typedef virSecret virshSecret; +void +virshSecretFree(virSecretPtr secret); +G_DEFINE_AUTOPTR_CLEANUP_FUNC(virshSecret, virshSecretFree); + int virshDomainState(vshControl *ctl, virDomainPtr dom, --=20 2.32.0 From nobody Sun May 19 10:57:28 2024 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=1632719298; cv=none; d=zohomail.com; s=zohoarc; b=KeqiwP0QzR/lxVJDqbf0LDQVgQoZ87pTmT/qT+ZjHQUWhkXh/RFvi+zJKJe1NrfV+RbELdALhKSUVA01hFkZNlnGJYVuLXYQ9mCJNCNYJLmTow2t91Z3VUDbJSi3ZiRTqeAqi33dAC3uKxBWegQ/UlPcJfhAZAJl8lOqAGF99U0= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1632719298; 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=GNmektXJ+k2COAP3wEie59f389zcvD7IDqym447a2BQ=; b=VHIJTuMdWmMLnLgbXYwjQ4DHyNH99NvFVYm1wlzjY+IxGCCOXHvcNz1Fn0HA18Kruy6vmXRpa+SX8E29XzvWmb2Le2fyRDcc+kHc4qzypWkEIBZFDi/ZYuBOAWhb3Mhz50iiC64SFY3TSB7YlZJ5WP2Wu4MHqkZzdGhwUCfBiHo= 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 1632719298887647.7325676413802; Sun, 26 Sep 2021 22:08:18 -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-173-xmcoC7pDNdi321cVqQHywA-1; Mon, 27 Sep 2021 01:08:15 -0400 Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.phx2.redhat.com [10.5.11.14]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id C1953362FE; Mon, 27 Sep 2021 05:08:08 +0000 (UTC) Received: from colo-mx.corp.redhat.com (colo-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.20]) by smtp.corp.redhat.com (Postfix) with ESMTPS id A07EE18A69; 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 72D2A1806D00; 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 18R580Ui004189 for ; Mon, 27 Sep 2021 01:08:00 -0400 Received: by smtp.corp.redhat.com (Postfix) id 8ACA2179B3; Mon, 27 Sep 2021 05:08:00 +0000 (UTC) Received: from localhost.localdomain (unknown [10.40.192.53]) by smtp.corp.redhat.com (Postfix) with ESMTP id C299D652A2 for ; Mon, 27 Sep 2021 05:07:59 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1632719297; 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=GNmektXJ+k2COAP3wEie59f389zcvD7IDqym447a2BQ=; b=FcKp9/81sRF8VZsVdwQ+AJAXRXoboxvWJc+PeimIcN4Ck+UT1cRBH6Nw/KUi/jN8ymFPb5 kdJckM7+/YPKTCY51JPJybMG4sQWcQzg5H7RWE/Pi3N2bFZhQmmT03QhOv75O2SPcqPUYC qRuB0cHvJffsxyfGxf1Cdsoas8moZH8= X-MC-Unique: xmcoC7pDNdi321cVqQHywA-1 From: Michal Privoznik To: libvir-list@redhat.com Subject: [PATCH 2/8] virsh: Add wrapper for virInterfaceFree Date: Mon, 27 Sep 2021 07:07:44 +0200 Message-Id: <0c207c9c0b8676115eb06262e993be46159904fd.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.14 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: 1632719300417100001 Content-Type: text/plain; charset="utf-8" Similarly to virshDomainFree add a wrapper for the snapshot object freeing function. Signed-off-by: Michal Privoznik Acked-by: Jonathon Jongsma --- build-aux/syntax-check.mk | 4 +-- tools/virsh-completer-interface.c | 3 +- tools/virsh-interface.c | 55 +++++++++---------------------- tools/virsh-util.c | 11 +++++++ tools/virsh-util.h | 5 +++ 5 files changed, 36 insertions(+), 42 deletions(-) diff --git a/build-aux/syntax-check.mk b/build-aux/syntax-check.mk index cb54c8ba36..84cb895d86 100644 --- a/build-aux/syntax-check.mk +++ b/build-aux/syntax-check.mk @@ -868,10 +868,10 @@ sc_gettext_init: $(_sc_search_regexp) =20 sc_prohibit_obj_free_apis_in_virsh: - @prohibit=3D'\bvir(Domain|DomainSnapshot|Secret)Free\b' \ + @prohibit=3D'\bvir(Domain|DomainSnapshot|Interface|Secret)Free\b' \ in_vc_files=3D'virsh.*\.[ch]$$' \ exclude=3D'sc_prohibit_obj_free_apis_in_virsh' \ - halt=3D'avoid using virDomain(Snapshot)Free in virsh, use virsh-prefixed = wrappers instead' \ + halt=3D'avoid using public virXXXFree in virsh, use virsh-prefixed wrappe= rs instead' \ $(_sc_search_regexp) =20 https_sites =3D www.libvirt.org diff --git a/tools/virsh-completer-interface.c b/tools/virsh-completer-inte= rface.c index 9a6603b27e..44ba35550a 100644 --- a/tools/virsh-completer-interface.c +++ b/tools/virsh-completer-interface.c @@ -21,6 +21,7 @@ #include =20 #include "virsh-completer-interface.h" +#include "virsh-util.h" #include "viralloc.h" #include "virsh.h" #include "virstring.h" @@ -59,7 +60,7 @@ virshInterfaceStringHelper(vshControl *ctl, } =20 for (i =3D 0; i < nifaces; i++) - virInterfaceFree(ifaces[i]); + virshInterfaceFree(ifaces[i]); g_free(ifaces); =20 return g_steal_pointer(&tmp); diff --git a/tools/virsh-interface.c b/tools/virsh-interface.c index f402119b68..0a8539da71 100644 --- a/tools/virsh-interface.c +++ b/tools/virsh-interface.c @@ -29,6 +29,7 @@ =20 #include #include "virsh-interface.h" +#include "virsh-util.h" =20 #include #include @@ -109,8 +110,8 @@ static bool cmdInterfaceEdit(vshControl *ctl, const vshCmd *cmd) { bool ret =3D false; - virInterfacePtr iface =3D NULL; - virInterfacePtr iface_edited =3D NULL; + g_autoptr(virshInterface) iface =3D NULL; + g_autoptr(virshInterface) iface_edited =3D NULL; unsigned int flags =3D VIR_INTERFACE_XML_INACTIVE; virshControl *priv =3D ctl->privData; =20 @@ -136,11 +137,6 @@ cmdInterfaceEdit(vshControl *ctl, const vshCmd *cmd) ret =3D true; =20 cleanup: - if (iface) - virInterfaceFree(iface); - if (iface_edited) - virInterfaceFree(iface_edited); - return ret; } =20 @@ -172,8 +168,7 @@ virshInterfaceListFree(struct virshInterfaceList *list) =20 if (list && list->ifaces) { for (i =3D 0; i < list->nifaces; i++) { - if (list->ifaces[i]) - virInterfaceFree(list->ifaces[i]); + virshInterfaceFree(list->ifaces[i]); } g_free(list->ifaces); } @@ -411,14 +406,13 @@ static const vshCmdOptDef opts_interface_name[] =3D { static bool cmdInterfaceName(vshControl *ctl, const vshCmd *cmd) { - virInterfacePtr iface; + g_autoptr(virshInterface) iface =3D NULL; =20 if (!(iface =3D virshCommandOptInterfaceBy(ctl, cmd, NULL, NULL, VIRSH_BYMAC))) return false; =20 vshPrint(ctl, "%s\n", virInterfaceGetName(iface)); - virInterfaceFree(iface); return true; } =20 @@ -448,14 +442,13 @@ static const vshCmdOptDef opts_interface_mac[] =3D { static bool cmdInterfaceMAC(vshControl *ctl, const vshCmd *cmd) { - virInterfacePtr iface; + g_autoptr(virshInterface) iface =3D NULL; =20 if (!(iface =3D virshCommandOptInterfaceBy(ctl, cmd, NULL, NULL, VIRSH_BYNAME))) return false; =20 vshPrint(ctl, "%s\n", virInterfaceGetMACString(iface)); - virInterfaceFree(iface); return true; } =20 @@ -484,7 +477,7 @@ static const vshCmdOptDef opts_interface_dumpxml[] =3D { static bool cmdInterfaceDumpXML(vshControl *ctl, const vshCmd *cmd) { - virInterfacePtr iface; + g_autoptr(virshInterface) iface =3D NULL; g_autofree char *dump =3D NULL; unsigned int flags =3D 0; =20 @@ -494,13 +487,10 @@ cmdInterfaceDumpXML(vshControl *ctl, const vshCmd *cm= d) if (!(iface =3D virshCommandOptInterface(ctl, cmd, NULL))) return false; =20 - if (!(dump =3D virInterfaceGetXMLDesc(iface, flags))) { - virInterfaceFree(iface); + if (!(dump =3D virInterfaceGetXMLDesc(iface, flags))) return false; - } =20 vshPrint(ctl, "%s", dump); - virInterfaceFree(iface); return true; } =20 @@ -530,7 +520,7 @@ static const vshCmdOptDef opts_interface_define[] =3D { static bool cmdInterfaceDefine(vshControl *ctl, const vshCmd *cmd) { - virInterfacePtr iface; + g_autoptr(virshInterface) iface =3D NULL; const char *from =3D NULL; g_autofree char *buffer =3D NULL; unsigned int flags =3D 0; @@ -552,7 +542,6 @@ cmdInterfaceDefine(vshControl *ctl, const vshCmd *cmd) =20 vshPrintExtra(ctl, _("Interface %s defined from %s\n"), virInterfaceGetName(iface), from); - virInterfaceFree(iface); return true; } =20 @@ -577,7 +566,7 @@ static const vshCmdOptDef opts_interface_undefine[] =3D= { static bool cmdInterfaceUndefine(vshControl *ctl, const vshCmd *cmd) { - virInterfacePtr iface; + g_autoptr(virshInterface) iface =3D NULL; const char *name; =20 if (!(iface =3D virshCommandOptInterface(ctl, cmd, &name))) @@ -585,12 +574,10 @@ cmdInterfaceUndefine(vshControl *ctl, const vshCmd *c= md) =20 if (virInterfaceUndefine(iface) < 0) { vshError(ctl, _("Failed to undefine interface %s"), name); - virInterfaceFree(iface); return false; } =20 vshPrintExtra(ctl, _("Interface %s undefined\n"), name); - virInterfaceFree(iface); return true; } =20 @@ -615,7 +602,7 @@ static const vshCmdOptDef opts_interface_start[] =3D { static bool cmdInterfaceStart(vshControl *ctl, const vshCmd *cmd) { - virInterfacePtr iface; + g_autoptr(virshInterface) iface =3D NULL; const char *name; =20 if (!(iface =3D virshCommandOptInterface(ctl, cmd, &name))) @@ -623,12 +610,10 @@ cmdInterfaceStart(vshControl *ctl, const vshCmd *cmd) =20 if (virInterfaceCreate(iface, 0) < 0) { vshError(ctl, _("Failed to start interface %s"), name); - virInterfaceFree(iface); return false; } =20 vshPrintExtra(ctl, _("Interface %s started\n"), name); - virInterfaceFree(iface); return true; } =20 @@ -653,7 +638,7 @@ static const vshCmdOptDef opts_interface_destroy[] =3D { static bool cmdInterfaceDestroy(vshControl *ctl, const vshCmd *cmd) { - virInterfacePtr iface; + g_autoptr(virshInterface) iface =3D NULL; const char *name; =20 if (!(iface =3D virshCommandOptInterface(ctl, cmd, &name))) @@ -661,12 +646,10 @@ cmdInterfaceDestroy(vshControl *ctl, const vshCmd *cm= d) =20 if (virInterfaceDestroy(iface, 0) < 0) { vshError(ctl, _("Failed to destroy interface %s"), name); - virInterfaceFree(iface); return false; } =20 vshPrintExtra(ctl, _("Interface %s destroyed\n"), name); - virInterfaceFree(iface); return false; } =20 @@ -809,7 +792,8 @@ static bool cmdInterfaceBridge(vshControl *ctl, const vshCmd *cmd) { bool ret =3D false; - virInterfacePtr if_handle =3D NULL, br_handle =3D NULL; + g_autoptr(virshInterface) if_handle =3D NULL; + g_autoptr(virshInterface) br_handle =3D NULL; const char *if_name, *br_name; char *if_type =3D NULL, *if2_name =3D NULL, *delay_str =3D NULL; bool stp =3D false, nostart =3D false; @@ -988,10 +972,6 @@ cmdInterfaceBridge(vshControl *ctl, const vshCmd *cmd) =20 ret =3D true; cleanup: - if (if_handle) - virInterfaceFree(if_handle); - if (br_handle) - virInterfaceFree(br_handle); VIR_FREE(if_xml); VIR_FREE(br_xml); VIR_FREE(if_type); @@ -1030,7 +1010,8 @@ static bool cmdInterfaceUnbridge(vshControl *ctl, const vshCmd *cmd) { bool ret =3D false; - virInterfacePtr if_handle =3D NULL, br_handle =3D NULL; + g_autoptr(virshInterface) if_handle =3D NULL; + g_autoptr(virshInterface) br_handle =3D NULL; const char *br_name; char *if_type =3D NULL, *if_name =3D NULL; bool nostart =3D false; @@ -1187,10 +1168,6 @@ cmdInterfaceUnbridge(vshControl *ctl, const vshCmd *= cmd) =20 ret =3D true; cleanup: - if (if_handle) - virInterfaceFree(if_handle); - if (br_handle) - virInterfaceFree(br_handle); VIR_FREE(if_xml); VIR_FREE(br_xml); VIR_FREE(if_type); diff --git a/tools/virsh-util.c b/tools/virsh-util.c index fb74514b3c..82523f2575 100644 --- a/tools/virsh-util.c +++ b/tools/virsh-util.c @@ -285,6 +285,17 @@ virshDomainSnapshotFree(virDomainSnapshotPtr snap) } =20 =20 +void +virshInterfaceFree(virInterfacePtr iface) +{ + if (!iface) + return; + + vshSaveLibvirtHelperError(); + virInterfaceFree(iface); /* sc_prohibit_obj_free_apis_in_virsh */ +} + + void virshSecretFree(virSecretPtr secret) { diff --git a/tools/virsh-util.h b/tools/virsh-util.h index f7e8116de3..7165755550 100644 --- a/tools/virsh-util.h +++ b/tools/virsh-util.h @@ -54,6 +54,11 @@ void virshDomainSnapshotFree(virDomainSnapshotPtr snap); G_DEFINE_AUTOPTR_CLEANUP_FUNC(virshDomainSnapshot, virshDomainSnapshotFree= ); =20 +typedef virInterface virshInterface; +void +virshInterfaceFree(virInterfacePtr iface); +G_DEFINE_AUTOPTR_CLEANUP_FUNC(virshInterface, virshInterfaceFree); + typedef virSecret virshSecret; void virshSecretFree(virSecretPtr secret); --=20 2.32.0 From nobody Sun May 19 10:57:28 2024 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 Acked-by: Jonathon Jongsma --- 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 From nobody Sun May 19 10:57:28 2024 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=1632719300; cv=none; d=zohomail.com; s=zohoarc; b=QQjXc5MzL2iF67SFerkyWJDqqp6LxokdJTKj0r2qawJmWdNzOZHMBPOqx+LT+XZQXuk0IPq4Rg0Nivh8YOjyUAoDgKhiFAcs9cpfw+joxE+WQDNwtuF+hGujHiTEZcCMalHkOXAalhOOwb6DC6ZT+YBu+c3uyNJxrrO5ZL9Qpwg= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1632719300; 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=RHIkpEiULOi7Fi/wkgXGlzv4KfU+1REJBXMDWIRKaII=; b=Y2W2vHA+I2ebfjuwCYcYcq6cgENjM1B3Yv8G4T1uJ4CH+ZUCNHAH5L0VlfUkFONg2WWxYSrZ4mx50CTs4S9NgucFlWcBQNIS/mGqJFPLTxuYCTE1vb0RcW/Y/1xWL2KY0psCze5Q0rYUri6yF5wHgnBqPFSKdsBd73MdGrv6d04= 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 1632719300920735.4201715216245; Sun, 26 Sep 2021 22:08:20 -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-479-j-mymzRyOr2awMOm0KHDtA-1; Mon, 27 Sep 2021 01:08:18 -0400 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.phx2.redhat.com [10.5.11.16]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 9D83136304; Mon, 27 Sep 2021 05:08:11 +0000 (UTC) Received: from colo-mx.corp.redhat.com (colo-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.20]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 7F23E5C1BB; Mon, 27 Sep 2021 05:08:11 +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 510BE1806D01; Mon, 27 Sep 2021 05:08:11 +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 18R582q4004201 for ; Mon, 27 Sep 2021 01:08:02 -0400 Received: by smtp.corp.redhat.com (Postfix) id A50B7179B3; Mon, 27 Sep 2021 05:08:02 +0000 (UTC) Received: from localhost.localdomain (unknown [10.40.192.53]) by smtp.corp.redhat.com (Postfix) with ESMTP id 173D8652A1 for ; Mon, 27 Sep 2021 05:08:01 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1632719299; 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=RHIkpEiULOi7Fi/wkgXGlzv4KfU+1REJBXMDWIRKaII=; b=FUIlDrz2ufKd6jNTazS/1L0IqaTt+8W67P/bVRTkHkz43+7oCupWKMIdfnsIGGc7ZVer2N 8XqHTTwRg1NNqBTlkzgFof17xLFQnczVmVl/rODDBCsJFO2hIX2LkP24sDTf0dRD1JK15G 8Cyo2yFgeSLiEWdm6rmsQryNCgH9Z/0= X-MC-Unique: j-mymzRyOr2awMOm0KHDtA-1 From: Michal Privoznik To: libvir-list@redhat.com Subject: [PATCH 4/8] virsh: Add wrapper for virStorageVolFree Date: Mon, 27 Sep 2021 07:07:46 +0200 Message-Id: <3fe845cc428bdaddc3ffcfefa1a6016b17363c20.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.16 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: 1632719302582100005 Content-Type: text/plain; charset="utf-8" Similarly to virshDomainFree add a wrapper for the snapshot object freeing function. Signed-off-by: Michal Privoznik Acked-by: Jonathon Jongsma --- build-aux/syntax-check.mk | 2 +- tools/virsh-completer-volume.c | 4 +- tools/virsh-domain.c | 3 +- tools/virsh-util.c | 11 ++++++ tools/virsh-util.h | 5 +++ tools/virsh-volume.c | 72 ++++++++++------------------------ 6 files changed, 40 insertions(+), 57 deletions(-) diff --git a/build-aux/syntax-check.mk b/build-aux/syntax-check.mk index 111d2109e8..2bdbd14c80 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|StoragePool)Fre= e\b' \ + @prohibit=3D'\bvir(Domain|DomainSnapshot|Interface|Secret|StoragePool|Sto= rageVol)Free\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-volume.c b/tools/virsh-completer-volume.c index 1d83643c69..ac3c472177 100644 --- a/tools/virsh-completer-volume.c +++ b/tools/virsh-completer-volume.c @@ -65,7 +65,7 @@ virshStorageVolNameCompleter(vshControl *ctl, =20 cleanup: for (i =3D 0; i < nvols; i++) - virStorageVolFree(vols[i]); + virshStorageVolFree(vols[i]); g_free(vols); return ret; } @@ -104,7 +104,7 @@ virshStorageVolKeyCompleter(vshControl *ctl, const char *key =3D virStorageVolGetKey(vols[j]); tmp[nvols] =3D g_strdup(key); nvols++; - virStorageVolFree(vols[j]); + virshStorageVolFree(vols[j]); } =20 g_free(vols); diff --git a/tools/virsh-domain.c b/tools/virsh-domain.c index 461a5e19f6..b1943b3875 100644 --- a/tools/virsh-domain.c +++ b/tools/virsh-domain.c @@ -3942,8 +3942,7 @@ cmdUndefine(vshControl *ctl, const vshCmd *cmd) for (i =3D 0; i < nvols; i++) { VIR_FREE(vols[i].source); VIR_FREE(vols[i].target); - if (vols[i].vol) - virStorageVolFree(vols[i].vol); + virshStorageVolFree(vols[i].vol); } VIR_FREE(vols); =20 diff --git a/tools/virsh-util.c b/tools/virsh-util.c index d537501387..c680c5b3d4 100644 --- a/tools/virsh-util.c +++ b/tools/virsh-util.c @@ -318,6 +318,17 @@ virshStoragePoolFree(virStoragePoolPtr pool) } =20 =20 +void +virshStorageVolFree(virStorageVolPtr vol) +{ + if (!vol) + return; + + vshSaveLibvirtHelperError(); + virStorageVolFree(vol); /* 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 3ff6f16784..ce3462a865 100644 --- a/tools/virsh-util.h +++ b/tools/virsh-util.h @@ -69,6 +69,11 @@ void virshStoragePoolFree(virStoragePoolPtr pool); G_DEFINE_AUTOPTR_CLEANUP_FUNC(virshStoragePool, virshStoragePoolFree); =20 +typedef virStorageVol virshStorageVol; +void +virshStorageVolFree(virStorageVolPtr vol); +G_DEFINE_AUTOPTR_CLEANUP_FUNC(virshStorageVol, virshStorageVolFree); + int virshDomainState(vshControl *ctl, virDomainPtr dom, diff --git a/tools/virsh-volume.c b/tools/virsh-volume.c index 6e8f7721a3..b896ebbbf9 100644 --- a/tools/virsh-volume.c +++ b/tools/virsh-volume.c @@ -153,8 +153,7 @@ virshCommandOptVolBy(vshControl *ctl, const vshCmd *cmd, vshError(ctl, _("Requested volume '%s' is not in pool '%s'"), n, virStoragePoolGetName(pool)); - virStorageVolFree(vol); - vol =3D NULL; + g_clear_pointer(&vol, virshStorageVolFree); } } } @@ -230,7 +229,7 @@ static bool cmdVolCreateAs(vshControl *ctl, const vshCmd *cmd) { g_autoptr(virshStoragePool) pool =3D NULL; - virStorageVolPtr vol =3D NULL; + g_autoptr(virshStorageVol) vol =3D NULL; g_autofree char *xml =3D NULL; bool printXML =3D vshCommandOptBool(cmd, "print-xml"); const char *name, *capacityStr =3D NULL, *allocationStr =3D NULL, *for= mat =3D NULL; @@ -287,7 +286,7 @@ cmdVolCreateAs(vshControl *ctl, const vshCmd *cmd) =20 /* Convert the snapshot parameters into backingStore XML */ if (snapshotStrVol) { - virStorageVolPtr snapVol; + g_autoptr(virshStorageVol) snapVol =3D NULL; g_autofree char *snapshotStrVolPath =3D NULL; /* Lookup snapshot backing volume. Try the backing-vol * parameter as a name */ @@ -330,7 +329,6 @@ cmdVolCreateAs(vshControl *ctl, const vshCmd *cmd) } =20 if ((snapshotStrVolPath =3D virStorageVolGetPath(snapVol)) =3D=3D = NULL) { - virStorageVolFree(snapVol); goto cleanup; } =20 @@ -343,9 +341,6 @@ cmdVolCreateAs(vshControl *ctl, const vshCmd *cmd) snapshotStrFormat); virBufferAdjustIndent(&buf, -2); virBufferAddLit(&buf, "\n"); - - /* Cleanup snapshot allocations */ - virStorageVolFree(snapVol); } =20 virBufferAdjustIndent(&buf, -2); @@ -366,8 +361,6 @@ cmdVolCreateAs(vshControl *ctl, const vshCmd *cmd) ret =3D true; =20 cleanup: - if (vol) - virStorageVolFree(vol); return ret; } =20 @@ -398,7 +391,7 @@ static bool cmdVolCreate(vshControl *ctl, const vshCmd *cmd) { g_autoptr(virshStoragePool) pool =3D NULL; - virStorageVolPtr vol; + g_autoptr(virshStorageVol) vol =3D NULL; const char *from =3D NULL; bool ret =3D false; unsigned int flags =3D 0; @@ -421,7 +414,6 @@ cmdVolCreate(vshControl *ctl, const vshCmd *cmd) if ((vol =3D virStorageVolCreateXML(pool, buffer, flags))) { vshPrintExtra(ctl, _("Vol %s created from %s\n"), virStorageVolGetName(vol), from); - virStorageVolFree(vol); ret =3D true; } else { vshError(ctl, _("Failed to create vol from %s"), from); @@ -468,7 +460,8 @@ static bool cmdVolCreateFrom(vshControl *ctl, const vshCmd *cmd) { g_autoptr(virshStoragePool) pool =3D NULL; - virStorageVolPtr newvol =3D NULL, inputvol =3D NULL; + g_autoptr(virshStorageVol) newvol =3D NULL; + g_autoptr(virshStorageVol) inputvol =3D NULL; const char *from =3D NULL; bool ret =3D false; g_autofree char *buffer =3D NULL; @@ -506,10 +499,6 @@ cmdVolCreateFrom(vshControl *ctl, const vshCmd *cmd) =20 ret =3D true; cleanup: - if (inputvol) - virStorageVolFree(inputvol); - if (newvol) - virStorageVolFree(newvol); return ret; } =20 @@ -574,7 +563,8 @@ static bool cmdVolClone(vshControl *ctl, const vshCmd *cmd) { g_autoptr(virshStoragePool) origpool =3D NULL; - virStorageVolPtr origvol =3D NULL, newvol =3D NULL; + g_autoptr(virshStorageVol) origvol =3D NULL; + g_autoptr(virshStorageVol) newvol =3D NULL; const char *name =3D NULL; g_autofree char *origxml =3D NULL; xmlChar *newxml =3D NULL; @@ -624,10 +614,6 @@ cmdVolClone(vshControl *ctl, const vshCmd *cmd) =20 cleanup: xmlFree(newxml); - if (origvol) - virStorageVolFree(origvol); - if (newvol) - virStorageVolFree(newvol); return ret; } =20 @@ -667,7 +653,7 @@ static bool cmdVolUpload(vshControl *ctl, const vshCmd *cmd) { const char *file =3D NULL; - virStorageVolPtr vol =3D NULL; + g_autoptr(virshStorageVol) vol =3D NULL; bool ret =3D false; int fd =3D -1; virStreamPtr st =3D NULL; @@ -745,8 +731,6 @@ cmdVolUpload(vshControl *ctl, const vshCmd *cmd) ret =3D true; =20 cleanup: - if (vol) - virStorageVolFree(vol); if (st) virStreamFree(st); VIR_FORCE_CLOSE(fd); @@ -789,7 +773,7 @@ static bool cmdVolDownload(vshControl *ctl, const vshCmd *cmd) { const char *file =3D NULL; - virStorageVolPtr vol =3D NULL; + g_autoptr(virshStorageVol) vol =3D NULL; bool ret =3D false; int fd =3D -1; virStreamPtr st =3D NULL; @@ -867,8 +851,6 @@ cmdVolDownload(vshControl *ctl, const vshCmd *cmd) VIR_FORCE_CLOSE(fd); if (!ret && created) unlink(file); - if (vol) - virStorageVolFree(vol); if (st) virStreamFree(st); return ret; @@ -901,7 +883,7 @@ static const vshCmdOptDef opts_vol_delete[] =3D { static bool cmdVolDelete(vshControl *ctl, const vshCmd *cmd) { - virStorageVolPtr vol; + g_autoptr(virshStorageVol) vol =3D NULL; bool ret =3D true; const char *name; bool delete_snapshots =3D vshCommandOptBool(cmd, "delete-snapshots"); @@ -920,7 +902,6 @@ cmdVolDelete(vshControl *ctl, const vshCmd *cmd) ret =3D false; } =20 - virStorageVolFree(vol); return ret; } =20 @@ -956,7 +937,7 @@ VIR_ENUM_IMPL(virshStorageVolWipeAlgorithm, static bool cmdVolWipe(vshControl *ctl, const vshCmd *cmd) { - virStorageVolPtr vol; + g_autoptr(virshStorageVol) vol =3D NULL; bool ret =3D false; const char *name; const char *algorithm_str =3D NULL; @@ -989,7 +970,6 @@ cmdVolWipe(vshControl *ctl, const vshCmd *cmd) vshPrintExtra(ctl, _("Vol %s wiped\n"), name); ret =3D true; out: - virStorageVolFree(vol); return ret; } =20 @@ -1043,7 +1023,7 @@ static bool cmdVolInfo(vshControl *ctl, const vshCmd *cmd) { virStorageVolInfo info; - virStorageVolPtr vol; + g_autoptr(virshStorageVol) vol =3D NULL; bool bytes =3D vshCommandOptBool(cmd, "bytes"); bool physical =3D vshCommandOptBool(cmd, "physical"); int rc; @@ -1063,7 +1043,6 @@ cmdVolInfo(vshControl *ctl, const vshCmd *cmd) rc =3D virStorageVolGetInfo(vol, &info); =20 if (rc < 0) { - virStorageVolFree(vol); return false; } =20 @@ -1090,7 +1069,6 @@ cmdVolInfo(vshControl *ctl, const vshCmd *cmd) vshPrint(ctl, "%-15s %2.2lf %s\n", _("Allocation:"), val, unit= ); } =20 - virStorageVolFree(vol); return true; } =20 @@ -1136,7 +1114,7 @@ static const vshCmdOptDef opts_vol_resize[] =3D { static bool cmdVolResize(vshControl *ctl, const vshCmd *cmd) { - virStorageVolPtr vol; + g_autoptr(virshStorageVol) vol =3D NULL; const char *capacityStr =3D NULL; unsigned long long capacity =3D 0; unsigned int flags =3D 0; @@ -1190,7 +1168,6 @@ cmdVolResize(vshControl *ctl, const vshCmd *cmd) } =20 cleanup: - virStorageVolFree(vol); return ret; } =20 @@ -1216,7 +1193,7 @@ static const vshCmdOptDef opts_vol_dumpxml[] =3D { static bool cmdVolDumpXML(vshControl *ctl, const vshCmd *cmd) { - virStorageVolPtr vol; + g_autoptr(virshStorageVol) vol =3D NULL; bool ret =3D true; char *dump; =20 @@ -1231,7 +1208,6 @@ cmdVolDumpXML(vshControl *ctl, const vshCmd *cmd) ret =3D false; } =20 - virStorageVolFree(vol); return ret; } =20 @@ -1263,8 +1239,7 @@ virshStorageVolListFree(struct virshStorageVolList *l= ist) =20 if (list && list->vols) { for (i =3D 0; i < list->nvols; i++) { - if (list->vols[i]) - virStorageVolFree(list->vols[i]); + virshStorageVolFree(list->vols[i]); } g_free(list->vols); } @@ -1537,14 +1512,13 @@ static const vshCmdOptDef opts_vol_name[] =3D { static bool cmdVolName(vshControl *ctl, const vshCmd *cmd) { - virStorageVolPtr vol; + g_autoptr(virshStorageVol) vol =3D NULL; =20 if (!(vol =3D virshCommandOptVolBy(ctl, cmd, "vol", NULL, NULL, VIRSH_BYUUID))) return false; =20 vshPrint(ctl, "%s\n", virStorageVolGetName(vol)); - virStorageVolFree(vol); return true; } =20 @@ -1574,7 +1548,7 @@ static bool cmdVolPool(vshControl *ctl, const vshCmd *cmd) { g_autoptr(virshStoragePool) pool =3D NULL; - virStorageVolPtr vol; + g_autoptr(virshStorageVol) vol =3D NULL; char uuid[VIR_UUID_STRING_BUFLEN]; =20 /* Use the supplied string to locate the volume */ @@ -1587,7 +1561,6 @@ cmdVolPool(vshControl *ctl, const vshCmd *cmd) pool =3D virStoragePoolLookupByVolume(vol); if (pool =3D=3D NULL) { vshError(ctl, "%s", _("failed to get parent pool")); - virStorageVolFree(vol); return false; } =20 @@ -1601,8 +1574,6 @@ cmdVolPool(vshControl *ctl, const vshCmd *cmd) vshPrint(ctl, "%s\n", virStoragePoolGetName(pool)); } =20 - /* Cleanup */ - virStorageVolFree(vol); return true; } =20 @@ -1628,13 +1599,12 @@ static const vshCmdOptDef opts_vol_key[] =3D { static bool cmdVolKey(vshControl *ctl, const vshCmd *cmd) { - virStorageVolPtr vol; + g_autoptr(virshStorageVol) vol =3D NULL; =20 if (!(vol =3D virshCommandOptVol(ctl, cmd, "vol", "pool", NULL))) return false; =20 vshPrint(ctl, "%s\n", virStorageVolGetKey(vol)); - virStorageVolFree(vol); return true; } =20 @@ -1660,19 +1630,17 @@ static const vshCmdOptDef opts_vol_path[] =3D { static bool cmdVolPath(vshControl *ctl, const vshCmd *cmd) { - virStorageVolPtr vol; + g_autoptr(virshStorageVol) vol =3D NULL; g_autofree char *StorageVolPath =3D NULL; =20 if (!(vol =3D virshCommandOptVol(ctl, cmd, "vol", "pool", NULL))) return false; =20 if ((StorageVolPath =3D virStorageVolGetPath(vol)) =3D=3D NULL) { - virStorageVolFree(vol); return false; } =20 vshPrint(ctl, "%s\n", StorageVolPath); - virStorageVolFree(vol); return true; } =20 --=20 2.32.0 From nobody Sun May 19 10:57:28 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 170.10.133.124 as permitted sender) client-ip=170.10.133.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.133.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=1632719303; cv=none; d=zohomail.com; s=zohoarc; b=MepeZqg2KZAOzyzfJWeRX3vzv16CY+f1PX6TyjKlSzavGbBfvablAC9AJ8e5eZFpGlopKcB95IGmijUIw5xDH3LP+KPj3CmQNrBBKVzwlZG+5eipKL4w9XKislSfqIrJXhVhWjcCA4PQRRktSeq3yzxyhpzxcyYyyIb+DFTm8rA= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1632719303; 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=lYFbyKbsr05V7e9TvahObqvCm59gO/wjjsiez54//68=; b=ZsPm2CUu6O3PcwZlz40KBg+Xf+boU5YpWOjj4FGJdKECdE+F8rIs0HtGKi7Sz9+ZJ7FO2yfvjBXBfJg9lGhcWB4h3x70gX7yXKE3FJ4ZYFkflbxfYqjV155LoBvDNoK2s7+xIlPqNCk56394+PieFjOHieRD2FDPPsJR3KS80lw= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 170.10.133.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.133.124]) by mx.zohomail.com with SMTPS id 1632719303985376.29889803260835; Sun, 26 Sep 2021 22:08:23 -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-478-qwzjX3Q4NKiAz0RxODA97g-1; Mon, 27 Sep 2021 01:08:20 -0400 Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.phx2.redhat.com [10.5.11.22]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 89EDE101F00E; Mon, 27 Sep 2021 05:08:14 +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 6608A1017CE4; Mon, 27 Sep 2021 05:08:14 +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 299E94E58F; Mon, 27 Sep 2021 05:08:14 +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 18R583U1004215 for ; Mon, 27 Sep 2021 01:08:03 -0400 Received: by smtp.corp.redhat.com (Postfix) id 9BCB0189C4; Mon, 27 Sep 2021 05:08:03 +0000 (UTC) Received: from localhost.localdomain (unknown [10.40.192.53]) by smtp.corp.redhat.com (Postfix) with ESMTP id 0EB9D179B3 for ; Mon, 27 Sep 2021 05:08:02 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1632719302; 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=lYFbyKbsr05V7e9TvahObqvCm59gO/wjjsiez54//68=; b=dcKQMJob/9NQEXRNsI7rUEVGFpTFHMpF7N6No0gVFHnkee/9jB5w6dm0/kpVy8JRzdZkd1 RFlqUycLKm3wNWj/UnNSH9KApezfFJOhJs32WBy/bWVQa+kaI9p0skMKdRcawYp88Swqpr 6nTUlcM2Nkw2c6rU4Lvn0D3GUqvQ2PA= X-MC-Unique: qwzjX3Q4NKiAz0RxODA97g-1 From: Michal Privoznik To: libvir-list@redhat.com Subject: [PATCH 5/8] virsh: Add wrapper for virNetworkFree Date: Mon, 27 Sep 2021 07:07:47 +0200 Message-Id: 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.84 on 10.5.11.22 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: 1632719304639100007 Content-Type: text/plain; charset="utf-8" Similarly to virshDomainFree add a wrapper for the snapshot object freeing function. Signed-off-by: Michal Privoznik Acked-by: Jonathon Jongsma --- build-aux/syntax-check.mk | 2 +- tools/virsh-completer-network.c | 8 ++-- tools/virsh-network.c | 75 ++++++++++----------------------- tools/virsh-util.c | 11 +++++ tools/virsh-util.h | 5 +++ 5 files changed, 43 insertions(+), 58 deletions(-) diff --git a/build-aux/syntax-check.mk b/build-aux/syntax-check.mk index 2bdbd14c80..0c0d844d6c 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|StoragePool|Sto= rageVol)Free\b' \ + @prohibit=3D'\bvir(Domain|DomainSnapshot|Interface|Network|Secret|Storage= Pool|StorageVol)Free\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-network.c b/tools/virsh-completer-networ= k.c index f9154f23a4..d498f59cb8 100644 --- a/tools/virsh-completer-network.c +++ b/tools/virsh-completer-network.c @@ -21,6 +21,7 @@ #include =20 #include "virsh-completer-network.h" +#include "virsh-util.h" #include "viralloc.h" #include "virsh-network.h" #include "virsh.h" @@ -60,7 +61,7 @@ virshNetworkNameCompleter(vshControl *ctl, ret =3D g_steal_pointer(&tmp); =20 for (i =3D 0; i < nnets; i++) - virNetworkFree(nets[i]); + virshNetworkFree(nets[i]); g_free(nets); return ret; } @@ -170,7 +171,7 @@ virshNetworkUUIDCompleter(vshControl *ctl, =20 cleanup: for (i =3D 0; i < nnets; i++) - virNetworkFree(nets[i]); + virshNetworkFree(nets[i]); g_free(nets); return ret; } @@ -183,7 +184,7 @@ virshNetworkDhcpMacCompleter(vshControl *ctl, { virshControl *priv =3D ctl->privData; virNetworkDHCPLeasePtr *leases =3D NULL; - virNetworkPtr network =3D NULL; + g_autoptr(virshNetwork) network =3D NULL; int nleases; size_t i =3D 0; char **ret =3D NULL; @@ -215,6 +216,5 @@ virshNetworkDhcpMacCompleter(vshControl *ctl, virNetworkDHCPLeaseFree(leases[i]); VIR_FREE(leases); } - virNetworkFree(network); return ret; } diff --git a/tools/virsh-network.c b/tools/virsh-network.c index 1442210278..02b22bf912 100644 --- a/tools/virsh-network.c +++ b/tools/virsh-network.c @@ -20,6 +20,7 @@ =20 #include #include "virsh-network.h" +#include "virsh-util.h" =20 #include "internal.h" #include "viralloc.h" @@ -155,7 +156,7 @@ static const vshCmdOptDef opts_network_autostart[] =3D { static bool cmdNetworkAutostart(vshControl *ctl, const vshCmd *cmd) { - virNetworkPtr network; + g_autoptr(virshNetwork) network =3D NULL; const char *name; int autostart; =20 @@ -169,7 +170,6 @@ cmdNetworkAutostart(vshControl *ctl, const vshCmd *cmd) vshError(ctl, _("failed to mark network %s as autostarted"), n= ame); else vshError(ctl, _("failed to unmark network %s as autostarted"),= name); - virNetworkFree(network); return false; } =20 @@ -178,7 +178,6 @@ cmdNetworkAutostart(vshControl *ctl, const vshCmd *cmd) else vshPrintExtra(ctl, _("Network %s unmarked as autostarted\n"), name= ); =20 - virNetworkFree(network); return true; } =20 @@ -207,7 +206,7 @@ static const vshCmdOptDef opts_network_create[] =3D { static bool cmdNetworkCreate(vshControl *ctl, const vshCmd *cmd) { - virNetworkPtr network; + g_autoptr(virshNetwork) network =3D NULL; const char *from =3D NULL; g_autofree char *buffer =3D NULL; unsigned int flags =3D 0; @@ -234,7 +233,6 @@ cmdNetworkCreate(vshControl *ctl, const vshCmd *cmd) =20 vshPrintExtra(ctl, _("Network %s created from %s\n"), virNetworkGetName(network), from); - virNetworkFree(network); return true; } =20 @@ -264,7 +262,7 @@ static const vshCmdOptDef opts_network_define[] =3D { static bool cmdNetworkDefine(vshControl *ctl, const vshCmd *cmd) { - virNetworkPtr network; + g_autoptr(virshNetwork) network =3D NULL; const char *from =3D NULL; g_autofree char *buffer =3D NULL; unsigned int flags =3D 0; @@ -291,7 +289,6 @@ cmdNetworkDefine(vshControl *ctl, const vshCmd *cmd) =20 vshPrintExtra(ctl, _("Network %s defined from %s\n"), virNetworkGetName(network), from); - virNetworkFree(network); return true; } =20 @@ -316,7 +313,7 @@ static const vshCmdOptDef opts_network_destroy[] =3D { static bool cmdNetworkDestroy(vshControl *ctl, const vshCmd *cmd) { - virNetworkPtr network; + g_autoptr(virshNetwork) network =3D NULL; bool ret =3D true; const char *name; =20 @@ -330,7 +327,6 @@ cmdNetworkDestroy(vshControl *ctl, const vshCmd *cmd) ret =3D false; } =20 - virNetworkFree(network); return ret; } =20 @@ -359,7 +355,7 @@ static const vshCmdOptDef opts_network_dumpxml[] =3D { static bool cmdNetworkDumpXML(vshControl *ctl, const vshCmd *cmd) { - virNetworkPtr network; + g_autoptr(virshNetwork) network =3D NULL; g_autofree char *dump =3D NULL; unsigned int flags =3D 0; =20 @@ -370,12 +366,10 @@ cmdNetworkDumpXML(vshControl *ctl, const vshCmd *cmd) flags |=3D VIR_NETWORK_XML_INACTIVE; =20 if (!(dump =3D virNetworkGetXMLDesc(network, flags))) { - virNetworkFree(network); return false; } =20 vshPrint(ctl, "%s", dump); - virNetworkFree(network); return true; } =20 @@ -400,7 +394,7 @@ static const vshCmdOptDef opts_network_info[] =3D { static bool cmdNetworkInfo(vshControl *ctl, const vshCmd *cmd) { - virNetworkPtr network; + g_autoptr(virshNetwork) network =3D NULL; char uuid[VIR_UUID_STRING_BUFLEN]; int autostart; int persistent =3D -1; @@ -435,7 +429,6 @@ cmdNetworkInfo(vshControl *ctl, const vshCmd *cmd) vshPrint(ctl, "%-15s %s\n", _("Bridge:"), bridge); =20 VIR_FREE(bridge); - virNetworkFree(network); return true; } =20 @@ -467,8 +460,7 @@ virshNetworkListFree(struct virshNetworkList *list) =20 if (list && list->nets) { for (i =3D 0; i < list->nnets; i++) { - if (list->nets[i]) - virNetworkFree(list->nets[i]); + virshNetworkFree(list->nets[i]); } g_free(list->nets); } @@ -626,8 +618,7 @@ virshNetworkListCollect(vshControl *ctl, =20 remove_entry: /* the pool has to be removed as it failed one of the filters */ - virNetworkFree(list->nets[i]); - list->nets[i] =3D NULL; + g_clear_pointer(&list->nets[i], virshNetworkFree); deleted++; } =20 @@ -825,14 +816,13 @@ static const vshCmdOptDef opts_network_name[] =3D { static bool cmdNetworkName(vshControl *ctl, const vshCmd *cmd) { - virNetworkPtr network; + g_autoptr(virshNetwork) network =3D NULL; =20 if (!(network =3D virshCommandOptNetworkBy(ctl, cmd, NULL, VIRSH_BYUUID))) return false; =20 vshPrint(ctl, "%s\n", virNetworkGetName(network)); - virNetworkFree(network); return true; } =20 @@ -857,7 +847,7 @@ static const vshCmdOptDef opts_network_start[] =3D { static bool cmdNetworkStart(vshControl *ctl, const vshCmd *cmd) { - virNetworkPtr network; + g_autoptr(virshNetwork) network =3D NULL; bool ret =3D true; const char *name =3D NULL; =20 @@ -870,7 +860,6 @@ cmdNetworkStart(vshControl *ctl, const vshCmd *cmd) vshError(ctl, _("Failed to start network %s"), name); ret =3D false; } - virNetworkFree(network); return ret; } =20 @@ -895,7 +884,7 @@ static const vshCmdOptDef opts_network_undefine[] =3D { static bool cmdNetworkUndefine(vshControl *ctl, const vshCmd *cmd) { - virNetworkPtr network; + g_autoptr(virshNetwork) network =3D NULL; bool ret =3D true; const char *name; =20 @@ -909,7 +898,6 @@ cmdNetworkUndefine(vshControl *ctl, const vshCmd *cmd) ret =3D false; } =20 - virNetworkFree(network); return ret; } =20 @@ -972,7 +960,7 @@ static bool cmdNetworkUpdate(vshControl *ctl, const vshCmd *cmd) { bool ret =3D false; - virNetworkPtr network; + g_autoptr(virshNetwork) network =3D NULL; const char *commandStr =3D NULL; const char *sectionStr =3D NULL; int command, section, parentIndex =3D -1; @@ -1071,7 +1059,6 @@ cmdNetworkUpdate(vshControl *ctl, const vshCmd *cmd) ret =3D true; cleanup: vshReportError(ctl); - virNetworkFree(network); return ret; } =20 @@ -1096,7 +1083,7 @@ static const vshCmdOptDef opts_network_uuid[] =3D { static bool cmdNetworkUuid(vshControl *ctl, const vshCmd *cmd) { - virNetworkPtr network; + g_autoptr(virshNetwork) network =3D NULL; char uuid[VIR_UUID_STRING_BUFLEN]; =20 if (!(network =3D virshCommandOptNetworkBy(ctl, cmd, NULL, @@ -1108,7 +1095,6 @@ cmdNetworkUuid(vshControl *ctl, const vshCmd *cmd) else vshError(ctl, "%s", _("failed to get network UUID")); =20 - virNetworkFree(network); return true; } =20 @@ -1150,8 +1136,8 @@ static bool cmdNetworkEdit(vshControl *ctl, const vshCmd *cmd) { bool ret =3D false; - virNetworkPtr network =3D NULL; - virNetworkPtr network_edited =3D NULL; + g_autoptr(virshNetwork) network =3D NULL; + g_autoptr(virshNetwork) network_edited =3D NULL; virshControl *priv =3D ctl->privData; =20 network =3D virshCommandOptNetwork(ctl, cmd, NULL); @@ -1176,11 +1162,6 @@ cmdNetworkEdit(vshControl *ctl, const vshCmd *cmd) ret =3D true; =20 cleanup: - if (network) - virNetworkFree(network); - if (network_edited) - virNetworkFree(network_edited); - return ret; } =20 @@ -1293,7 +1274,7 @@ static const vshCmdOptDef opts_network_event[] =3D { static bool cmdNetworkEvent(vshControl *ctl, const vshCmd *cmd) { - virNetworkPtr net =3D NULL; + g_autoptr(virshNetwork) net =3D NULL; bool ret =3D false; int eventId =3D -1; int timeout =3D 0; @@ -1362,8 +1343,6 @@ cmdNetworkEvent(vshControl *ctl, const vshCmd *cmd) if (eventId >=3D 0 && virConnectNetworkEventDeregisterAny(priv->conn, eventId) < 0) ret =3D false; - if (net) - virNetworkFree(net); return ret; } =20 @@ -1417,7 +1396,7 @@ cmdNetworkDHCPLeases(vshControl *ctl, const vshCmd *c= md) bool ret =3D false; size_t i; unsigned int flags =3D 0; - virNetworkPtr network =3D NULL; + g_autoptr(virshNetwork) network =3D NULL; g_autoptr(vshTable) table =3D NULL; =20 if (vshCommandOptStringReq(ctl, cmd, "mac", &mac) < 0) @@ -1477,7 +1456,6 @@ cmdNetworkDHCPLeases(vshControl *ctl, const vshCmd *c= md) virNetworkDHCPLeaseFree(leases[i]); VIR_FREE(leases); } - virNetworkFree(network); return ret; } =20 @@ -1511,7 +1489,7 @@ cmdNetworkPortCreate(vshControl *ctl, const vshCmd *c= md) const char *from =3D NULL; bool ret =3D false; char *buffer =3D NULL; - virNetworkPtr network =3D NULL; + g_autoptr(virshNetwork) network =3D NULL; unsigned int flags =3D 0; =20 network =3D virshCommandOptNetwork(ctl, cmd, NULL); @@ -1546,8 +1524,6 @@ cmdNetworkPortCreate(vshControl *ctl, const vshCmd *c= md) VIR_FREE(buffer); if (port) virNetworkPortFree(port); - if (network) - virNetworkFree(network); return ret; } =20 @@ -1573,7 +1549,7 @@ static const vshCmdOptDef opts_network_port_dumpxml[]= =3D { static bool cmdNetworkPortDumpXML(vshControl *ctl, const vshCmd *cmd) { - virNetworkPtr network; + g_autoptr(virshNetwork) network =3D NULL; virNetworkPortPtr port =3D NULL; bool ret =3D true; g_autofree char *dump =3D NULL; @@ -1596,8 +1572,6 @@ cmdNetworkPortDumpXML(vshControl *ctl, const vshCmd *= cmd) cleanup: if (port) virNetworkPortFree(port); - if (network) - virNetworkFree(network); return ret; } =20 @@ -1624,7 +1598,7 @@ static const vshCmdOptDef opts_network_port_delete[] = =3D { static bool cmdNetworkPortDelete(vshControl *ctl, const vshCmd *cmd) { - virNetworkPtr network =3D NULL; + g_autoptr(virshNetwork) network =3D NULL; virNetworkPortPtr port =3D NULL; bool ret =3D true; char uuidstr[VIR_UUID_STRING_BUFLEN]; @@ -1649,8 +1623,6 @@ cmdNetworkPortDelete(vshControl *ctl, const vshCmd *c= md) cleanup: if (port) virNetworkPortFree(port); - if (network) - virNetworkFree(network); return ret; } =20 @@ -1703,7 +1675,7 @@ virshNetworkPortListCollect(vshControl *ctl, { struct virshNetworkPortList *list =3D g_new0(struct virshNetworkPortLi= st, 1); int ret; - virNetworkPtr network =3D NULL; + g_autoptr(virshNetwork) network =3D NULL; bool success =3D false; =20 if (!(network =3D virshCommandOptNetwork(ctl, cmd, NULL))) @@ -1729,9 +1701,6 @@ virshNetworkPortListCollect(vshControl *ctl, list =3D NULL; } =20 - if (network) - virNetworkFree(network); - return list; } =20 diff --git a/tools/virsh-util.c b/tools/virsh-util.c index c680c5b3d4..f7b649983e 100644 --- a/tools/virsh-util.c +++ b/tools/virsh-util.c @@ -296,6 +296,17 @@ virshInterfaceFree(virInterfacePtr iface) } =20 =20 +void +virshNetworkFree(virNetworkPtr network) +{ + if (!network) + return; + + vshSaveLibvirtHelperError(); + virNetworkFree(network); /* sc_prohibit_obj_free_apis_in_virsh */ +} + + void virshSecretFree(virSecretPtr secret) { diff --git a/tools/virsh-util.h b/tools/virsh-util.h index ce3462a865..e8df0a6618 100644 --- a/tools/virsh-util.h +++ b/tools/virsh-util.h @@ -59,6 +59,11 @@ void virshInterfaceFree(virInterfacePtr iface); G_DEFINE_AUTOPTR_CLEANUP_FUNC(virshInterface, virshInterfaceFree); =20 +typedef virNetwork virshNetwork; +void +virshNetworkFree(virNetworkPtr network); +G_DEFINE_AUTOPTR_CLEANUP_FUNC(virshNetwork, virshNetworkFree); + typedef virSecret virshSecret; void virshSecretFree(virSecretPtr secret); --=20 2.32.0 From nobody Sun May 19 10:57:28 2024 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=1632719352; cv=none; d=zohomail.com; s=zohoarc; b=Avrx1Z+ty/Nkf8103OSjL0srL2dP99fGDRSSRfGhYq1eux4F5di4jT94YVz1j2zt1EF7gh2PpkzDDdOawqXrbITilvzygEHaqhhrXH4KloboOkMfD30fqHiCiUs17KKsF6tSwOXYutbm5ceWKJM7KZHdfu6VMs2V+JB+XX2q1h0= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1632719352; 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=IkSMyrasqaVxygbUEhQSp+KMRZ24xyJKUL2fr1Jdrxc=; b=OF01/L8ks4+DAGm8KPPrGtquy2+gGdqsNp+AByw6WsVqB0FsxYuDNQQ1yVleSGvVt0Uz5kqUZAZsNqZ4rS/y31XGnnfv6LsVDdCRBLxf4gLo5TddboNIaL67zx9197w+twiUa9B6UK0UVVIlmvf+HxL2n26UzO8HFR8JK1fcXjY= 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 1632719352194102.74060129416773; Sun, 26 Sep 2021 22:09:12 -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-29-7Lb4zWbEPaqlRS0pdq9vMg-1; Mon, 27 Sep 2021 01:08:22 -0400 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.phx2.redhat.com [10.5.11.16]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 57F40101F008; Mon, 27 Sep 2021 05:08:17 +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 38D1E5C1BB; Mon, 27 Sep 2021 05:08:17 +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 072594EA3A; Mon, 27 Sep 2021 05:08:17 +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 18R5848a004230 for ; Mon, 27 Sep 2021 01:08:04 -0400 Received: by smtp.corp.redhat.com (Postfix) id 938FD53E08; Mon, 27 Sep 2021 05:08:04 +0000 (UTC) Received: from localhost.localdomain (unknown [10.40.192.53]) by smtp.corp.redhat.com (Postfix) with ESMTP id 057B860657 for ; Mon, 27 Sep 2021 05:08:03 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1632719351; 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=IkSMyrasqaVxygbUEhQSp+KMRZ24xyJKUL2fr1Jdrxc=; b=J0k0FzW/Bi9b8fPlL5i7qAGf8z9zjx5ZFydlJo6LruT7sUSGeLu5kWIiWqzIJ1jgaF2gaB PGxnOE0yOyNhOOQv4PGI1hwBxxrbWZtuND+dohFi1be0ShqD1yVLpBkj7p7cjSBx15Cp0I zfvLOqS5qif/B/pCsZXv005/kVM3Q+0= X-MC-Unique: 7Lb4zWbEPaqlRS0pdq9vMg-1 From: Michal Privoznik To: libvir-list@redhat.com Subject: [PATCH 6/8] virsh: Add wrapper for virNodeDeviceFree Date: Mon, 27 Sep 2021 07:07:48 +0200 Message-Id: <58f9333f85be3af0a6f7269481cf09f943e798d2.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.16 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: 1632719353778100001 Content-Type: text/plain; charset="utf-8" Similarly to virshDomainFree add a wrapper for the snapshot object freeing function. Signed-off-by: Michal Privoznik Acked-by: Jonathon Jongsma --- build-aux/syntax-check.mk | 2 +- tools/virsh-completer-nodedev.c | 3 +- tools/virsh-nodedev.c | 49 ++++++++++----------------------- tools/virsh-util.c | 11 ++++++++ tools/virsh-util.h | 5 ++++ 5 files changed, 34 insertions(+), 36 deletions(-) diff --git a/build-aux/syntax-check.mk b/build-aux/syntax-check.mk index 0c0d844d6c..6c230826bd 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|Network|Secret|Storage= Pool|StorageVol)Free\b' \ + @prohibit=3D'\bvir(Domain|DomainSnapshot|Interface|Network|NodeDevice|Sec= ret|StoragePool|StorageVol)Free\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-nodedev.c b/tools/virsh-completer-nodede= v.c index d595b687fd..d10bf2b78c 100644 --- a/tools/virsh-completer-nodedev.c +++ b/tools/virsh-completer-nodedev.c @@ -21,6 +21,7 @@ #include =20 #include "virsh-completer-nodedev.h" +#include "virsh-util.h" #include "conf/node_device_conf.h" #include "viralloc.h" #include "virsh-nodedev.h" @@ -58,7 +59,7 @@ virshNodeDeviceNameCompleter(vshControl *ctl, ret =3D g_steal_pointer(&tmp); =20 for (i =3D 0; i < ndevs; i++) - virNodeDeviceFree(devs[i]); + virshNodeDeviceFree(devs[i]); g_free(devs); return ret; } diff --git a/tools/virsh-nodedev.c b/tools/virsh-nodedev.c index f72359121f..c989a77ad2 100644 --- a/tools/virsh-nodedev.c +++ b/tools/virsh-nodedev.c @@ -20,6 +20,7 @@ =20 #include #include "virsh-nodedev.h" +#include "virsh-util.h" =20 #include "internal.h" #include "viralloc.h" @@ -55,7 +56,7 @@ static const vshCmdOptDef opts_node_device_create[] =3D { static bool cmdNodeDeviceCreate(vshControl *ctl, const vshCmd *cmd) { - virNodeDevicePtr dev =3D NULL; + g_autoptr(virshNodeDevice) dev =3D NULL; const char *from =3D NULL; g_autofree char *buffer =3D NULL; virshControl *priv =3D ctl->privData; @@ -73,7 +74,6 @@ cmdNodeDeviceCreate(vshControl *ctl, const vshCmd *cmd) =20 vshPrintExtra(ctl, _("Node device %s created from %s\n"), virNodeDeviceGetName(dev), from); - virNodeDeviceFree(dev); return true; } =20 @@ -140,7 +140,7 @@ vshFindNodeDevice(vshControl *ctl, const char *value) static bool cmdNodeDeviceDestroy(vshControl *ctl, const vshCmd *cmd) { - virNodeDevice *dev =3D NULL; + g_autoptr(virshNodeDevice) dev =3D NULL; bool ret =3D false; const char *device_value =3D NULL; =20 @@ -160,8 +160,6 @@ cmdNodeDeviceDestroy(vshControl *ctl, const vshCmd *cmd) =20 ret =3D true; cleanup: - if (dev) - virNodeDeviceFree(dev); return ret; } =20 @@ -207,8 +205,7 @@ virshNodeDeviceListFree(struct virshNodeDeviceList *lis= t) =20 if (list && list->devices) { for (i =3D 0; i < list->ndevices; i++) { - if (list->devices[i]) - virNodeDeviceFree(list->devices[i]); + virshNodeDeviceFree(list->devices[i]); } g_free(list->devices); } @@ -327,8 +324,7 @@ virshNodeDeviceListCollect(vshControl *ctl, =20 remove_entry: /* the device has to be removed as it failed one of the filters */ - virNodeDeviceFree(list->devices[i]); - list->devices[i] =3D NULL; + g_clear_pointer(&list->devices[i], virshNodeDeviceFree); deleted++; } =20 @@ -576,7 +572,7 @@ static const vshCmdOptDef opts_node_device_dumpxml[] = =3D { static bool cmdNodeDeviceDumpXML(vshControl *ctl, const vshCmd *cmd) { - virNodeDevicePtr device =3D NULL; + g_autoptr(virshNodeDevice) device =3D NULL; g_autofree char *xml =3D NULL; const char *device_value =3D NULL; bool ret =3D false; @@ -596,8 +592,6 @@ cmdNodeDeviceDumpXML(vshControl *ctl, const vshCmd *cmd) =20 ret =3D true; cleanup: - if (device) - virNodeDeviceFree(device); return ret; } =20 @@ -634,7 +628,7 @@ cmdNodeDeviceDetach(vshControl *ctl, const vshCmd *cmd) { const char *name =3D NULL; const char *driverName =3D NULL; - virNodeDevicePtr device; + g_autoptr(virshNodeDevice) device =3D NULL; bool ret =3D true; virshControl *priv =3D ctl->privData; =20 @@ -664,7 +658,6 @@ cmdNodeDeviceDetach(vshControl *ctl, const vshCmd *cmd) else vshError(ctl, _("Failed to detach device %s"), name); =20 - virNodeDeviceFree(device); return ret; } =20 @@ -696,7 +689,7 @@ static bool cmdNodeDeviceReAttach(vshControl *ctl, const vshCmd *cmd) { const char *name =3D NULL; - virNodeDevicePtr device; + g_autoptr(virshNodeDevice) device =3D NULL; bool ret =3D true; virshControl *priv =3D ctl->privData; =20 @@ -715,7 +708,6 @@ cmdNodeDeviceReAttach(vshControl *ctl, const vshCmd *cm= d) ret =3D false; } =20 - virNodeDeviceFree(device); return ret; } =20 @@ -747,7 +739,7 @@ static bool cmdNodeDeviceReset(vshControl *ctl, const vshCmd *cmd) { const char *name =3D NULL; - virNodeDevicePtr device; + g_autoptr(virshNodeDevice) device =3D NULL; bool ret =3D true; virshControl *priv =3D ctl->privData; =20 @@ -766,7 +758,6 @@ cmdNodeDeviceReset(vshControl *ctl, const vshCmd *cmd) ret =3D false; } =20 - virNodeDeviceFree(device); return ret; } =20 @@ -910,7 +901,7 @@ static const vshCmdOptDef opts_node_device_event[] =3D { static bool cmdNodeDeviceEvent(vshControl *ctl, const vshCmd *cmd) { - virNodeDevicePtr dev =3D NULL; + g_autoptr(virshNodeDevice) dev =3D NULL; bool ret =3D false; int eventId =3D -1; int timeout =3D 0; @@ -988,8 +979,6 @@ cmdNodeDeviceEvent(vshControl *ctl, const vshCmd *cmd) if (eventId >=3D 0 && virConnectNodeDeviceEventDeregisterAny(priv->conn, eventId) < 0) ret =3D false; - if (dev) - virNodeDeviceFree(dev); return ret; } =20 @@ -1020,7 +1009,7 @@ static const vshCmdOptDef opts_node_device_undefine[]= =3D { static bool cmdNodeDeviceUndefine(vshControl *ctl, const vshCmd *cmd G_GNUC_UNUSED) { - virNodeDevice *dev =3D NULL; + g_autoptr(virshNodeDevice) dev =3D NULL; bool ret =3D false; const char *device_value =3D NULL; =20 @@ -1041,8 +1030,6 @@ cmdNodeDeviceUndefine(vshControl *ctl, const vshCmd *= cmd G_GNUC_UNUSED) =20 ret =3D true; cleanup: - if (dev) - virNodeDeviceFree(dev); return ret; } =20 @@ -1071,7 +1058,7 @@ static const vshCmdOptDef opts_node_device_define[] = =3D { static bool cmdNodeDeviceDefine(vshControl *ctl, const vshCmd *cmd G_GNUC_UNUSED) { - virNodeDevice *dev =3D NULL; + g_autoptr(virshNodeDevice) dev =3D NULL; const char *from =3D NULL; g_autofree char *buffer =3D NULL; virshControl *priv =3D ctl->privData; @@ -1089,7 +1076,6 @@ cmdNodeDeviceDefine(vshControl *ctl, const vshCmd *cm= d G_GNUC_UNUSED) =20 vshPrintExtra(ctl, _("Node device '%s' defined from '%s'\n"), virNodeDeviceGetName(dev), from); - virNodeDeviceFree(dev); return true; } =20 @@ -1121,7 +1107,7 @@ static bool cmdNodeDeviceStart(vshControl *ctl, const vshCmd *cmd) { const char *name =3D NULL; - virNodeDevice *device; + g_autoptr(virshNodeDevice) device =3D NULL; bool ret =3D true; virshControl *priv =3D ctl->privData; =20 @@ -1140,7 +1126,6 @@ cmdNodeDeviceStart(vshControl *ctl, const vshCmd *cmd) ret =3D false; } =20 - virNodeDeviceFree(device); return ret; } =20 @@ -1175,7 +1160,7 @@ static const vshCmdOptDef opts_node_device_autostart[= ] =3D { static bool cmdNodeDeviceAutostart(vshControl *ctl, const vshCmd *cmd) { - virNodeDevice *dev =3D NULL; + g_autoptr(virshNodeDevice) dev =3D NULL; bool ret =3D false; const char *name =3D NULL; int autostart; @@ -1204,8 +1189,6 @@ cmdNodeDeviceAutostart(vshControl *ctl, const vshCmd = *cmd) =20 ret =3D true; cleanup: - if (dev) - virNodeDeviceFree(dev); return ret; } =20 @@ -1237,7 +1220,7 @@ static const vshCmdOptDef opts_node_device_info[] =3D= { static bool cmdNodeDeviceInfo(vshControl *ctl, const vshCmd *cmd) { - virNodeDevicePtr device =3D NULL; + g_autoptr(virshNodeDevice) device =3D NULL; const char *device_value =3D NULL; bool ret =3D false; int autostart; @@ -1265,8 +1248,6 @@ cmdNodeDeviceInfo(vshControl *ctl, const vshCmd *cmd) =20 ret =3D true; cleanup: - if (device) - virNodeDeviceFree(device); return ret; } =20 diff --git a/tools/virsh-util.c b/tools/virsh-util.c index f7b649983e..5034f4773f 100644 --- a/tools/virsh-util.c +++ b/tools/virsh-util.c @@ -307,6 +307,17 @@ virshNetworkFree(virNetworkPtr network) } =20 =20 +void +virshNodeDeviceFree(virNodeDevicePtr device) +{ + if (!device) + return; + + vshSaveLibvirtHelperError(); + virNodeDeviceFree(device); /* sc_prohibit_obj_free_apis_in_virsh */ +} + + void virshSecretFree(virSecretPtr secret) { diff --git a/tools/virsh-util.h b/tools/virsh-util.h index e8df0a6618..06e311b21a 100644 --- a/tools/virsh-util.h +++ b/tools/virsh-util.h @@ -64,6 +64,11 @@ void virshNetworkFree(virNetworkPtr network); G_DEFINE_AUTOPTR_CLEANUP_FUNC(virshNetwork, virshNetworkFree); =20 +typedef virNodeDevice virshNodeDevice; +void +virshNodeDeviceFree(virNodeDevicePtr device); +G_DEFINE_AUTOPTR_CLEANUP_FUNC(virshNodeDevice, virshNodeDeviceFree); + typedef virSecret virshSecret; void virshSecretFree(virSecretPtr secret); --=20 2.32.0 From nobody Sun May 19 10:57:28 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 170.10.133.124 as permitted sender) client-ip=170.10.133.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.133.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=1632719358; cv=none; d=zohomail.com; s=zohoarc; b=ma60bBiMK8sbSUW35diB8gJ9HmiN8Dwj/ewzY/RcfgKdurWZTFAUM9irMBHfqGtgeMEMUzfAk5X39FGlXTCcDJP/GBgrFEAP91UILaS4+mVo8AGC8ISxZWl8DJaIWnvQsQj16WIbrr2o4wfjce8Fns9V6ctzGT4NwKvarDY3QIs= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1632719358; 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=ABf63e5i4xZrtFJqMTacgBaD4etIgpXL7lWOYfx0YZM=; b=m7aQtKG6eT/6onFzJEq+CpPmjiv1RsNTXS/jMV4U9TvekSooFfUtuScO5zONz0yVaMfIrzQY2ilhhc4xr+M3htygDC/PjGnV5I12ZfQMf5iko5hGe4E0Qoh9R8tbpfSN7tXHyiwNPEiXZwTaw1Hg95lGwXCiWv76g25MWBPRjw0= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 170.10.133.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.133.124]) by mx.zohomail.com with SMTPS id 1632719358285317.25603490773983; Sun, 26 Sep 2021 22:09:18 -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-58-ttMn2zyEPtevETP3uv4zRg-1; Mon, 27 Sep 2021 01:08:16 -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 7CC7E19057AB; Mon, 27 Sep 2021 05:08:11 +0000 (UTC) Received: from colo-mx.corp.redhat.com (colo-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.20]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 5EA666B559; Mon, 27 Sep 2021 05:08:11 +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 2E1DC180BAD2; Mon, 27 Sep 2021 05:08:11 +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 18R585sG004240 for ; Mon, 27 Sep 2021 01:08:05 -0400 Received: by smtp.corp.redhat.com (Postfix) id 8987C18B5E; Mon, 27 Sep 2021 05:08:05 +0000 (UTC) Received: from localhost.localdomain (unknown [10.40.192.53]) by smtp.corp.redhat.com (Postfix) with ESMTP id EED06189C4 for ; Mon, 27 Sep 2021 05:08:04 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1632719357; 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=ABf63e5i4xZrtFJqMTacgBaD4etIgpXL7lWOYfx0YZM=; b=D2cbyi1qkdr+IPis0P0pQ0Wlc3U8JFRoiGGM9aB8fdGA6EeY4sLE2bTd88o5jCOCW/S0fy zviRZc5WebAvoQChORc6T8xzW7RHZCFncErI+ttpjlDb0VTkI7UTuYreuUY8tvGG+pkGA4 o5mCbDw9btgwwjebDCEHIaE0S4eunyQ= X-MC-Unique: ttMn2zyEPtevETP3uv4zRg-1 From: Michal Privoznik To: libvir-list@redhat.com Subject: [PATCH 7/8] virsh: Add wrapper for virNWFilterFree Date: Mon, 27 Sep 2021 07:07:49 +0200 Message-Id: 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: 1632719360126100001 Content-Type: text/plain; charset="utf-8" Similarly to virshDomainFree add a wrapper for the snapshot object freeing function. Signed-off-by: Michal Privoznik Acked-by: Jonathon Jongsma --- build-aux/syntax-check.mk | 2 +- tools/virsh-completer-nwfilter.c | 3 ++- tools/virsh-nwfilter.c | 22 +++++++--------------- tools/virsh-util.c | 11 +++++++++++ tools/virsh-util.h | 5 +++++ 5 files changed, 26 insertions(+), 17 deletions(-) diff --git a/build-aux/syntax-check.mk b/build-aux/syntax-check.mk index 6c230826bd..5daf5afcd0 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|Network|NodeDevice|Sec= ret|StoragePool|StorageVol)Free\b' \ + @prohibit=3D'\bvir(Domain|DomainSnapshot|Interface|Network|NodeDevice|NWF= ilter|Secret|StoragePool|StorageVol)Free\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-nwfilter.c b/tools/virsh-completer-nwfil= ter.c index 859f72f6e9..9850dbba5d 100644 --- a/tools/virsh-completer-nwfilter.c +++ b/tools/virsh-completer-nwfilter.c @@ -21,6 +21,7 @@ #include =20 #include "virsh-completer-nwfilter.h" +#include "virsh-util.h" #include "viralloc.h" #include "virsh.h" #include "virstring.h" @@ -56,7 +57,7 @@ virshNWFilterNameCompleter(vshControl *ctl, ret =3D g_steal_pointer(&tmp); =20 for (i =3D 0; i < nnwfilters; i++) - virNWFilterFree(nwfilters[i]); + virshNWFilterFree(nwfilters[i]); g_free(nwfilters); return ret; } diff --git a/tools/virsh-nwfilter.c b/tools/virsh-nwfilter.c index 33164f623f..09ceaf6ec9 100644 --- a/tools/virsh-nwfilter.c +++ b/tools/virsh-nwfilter.c @@ -20,6 +20,7 @@ =20 #include #include "virsh-nwfilter.h" +#include "virsh-util.h" =20 #include "internal.h" #include "viralloc.h" @@ -91,7 +92,7 @@ static const vshCmdOptDef opts_nwfilter_define[] =3D { static bool cmdNWFilterDefine(vshControl *ctl, const vshCmd *cmd) { - virNWFilterPtr nwfilter; + g_autoptr(virshNWFilter) nwfilter =3D NULL; const char *from =3D NULL; bool ret =3D true; g_autofree char *buffer =3D NULL; @@ -115,7 +116,6 @@ cmdNWFilterDefine(vshControl *ctl, const vshCmd *cmd) if (nwfilter !=3D NULL) { vshPrintExtra(ctl, _("Network filter %s defined from %s\n"), virNWFilterGetName(nwfilter), from); - virNWFilterFree(nwfilter); } else { vshError(ctl, _("Failed to define network filter from %s"), from); ret =3D false; @@ -149,7 +149,7 @@ static const vshCmdOptDef opts_nwfilter_undefine[] =3D { static bool cmdNWFilterUndefine(vshControl *ctl, const vshCmd *cmd) { - virNWFilterPtr nwfilter; + g_autoptr(virshNWFilter) nwfilter =3D NULL; bool ret =3D true; const char *name; =20 @@ -163,7 +163,6 @@ cmdNWFilterUndefine(vshControl *ctl, const vshCmd *cmd) ret =3D false; } =20 - virNWFilterFree(nwfilter); return ret; } =20 @@ -193,7 +192,7 @@ static const vshCmdOptDef opts_nwfilter_dumpxml[] =3D { static bool cmdNWFilterDumpXML(vshControl *ctl, const vshCmd *cmd) { - virNWFilterPtr nwfilter; + g_autoptr(virshNWFilter) nwfilter =3D NULL; bool ret =3D true; g_autofree char *dump =3D NULL; =20 @@ -207,7 +206,6 @@ cmdNWFilterDumpXML(vshControl *ctl, const vshCmd *cmd) ret =3D false; } =20 - virNWFilterFree(nwfilter); return ret; } =20 @@ -239,8 +237,7 @@ virshNWFilterListFree(struct virshNWFilterList *list) =20 if (list && list->filters) { for (i =3D 0; i < list->nfilters; i++) { - if (list->filters[i]) - virNWFilterFree(list->filters[i]); + virshNWFilterFree(list->filters[i]); } g_free(list->filters); } @@ -418,8 +415,8 @@ static bool cmdNWFilterEdit(vshControl *ctl, const vshCmd *cmd) { bool ret =3D false; - virNWFilterPtr nwfilter =3D NULL; - virNWFilterPtr nwfilter_edited =3D NULL; + g_autoptr(virshNWFilter) nwfilter =3D NULL; + g_autoptr(virshNWFilter) nwfilter_edited =3D NULL; virshControl *priv =3D ctl->privData; =20 nwfilter =3D virshCommandOptNWFilter(ctl, cmd, NULL); @@ -445,11 +442,6 @@ cmdNWFilterEdit(vshControl *ctl, const vshCmd *cmd) ret =3D true; =20 cleanup: - if (nwfilter) - virNWFilterFree(nwfilter); - if (nwfilter_edited) - virNWFilterFree(nwfilter_edited); - return ret; } =20 diff --git a/tools/virsh-util.c b/tools/virsh-util.c index 5034f4773f..fc2839d8fc 100644 --- a/tools/virsh-util.c +++ b/tools/virsh-util.c @@ -318,6 +318,17 @@ virshNodeDeviceFree(virNodeDevicePtr device) } =20 =20 +void +virshNWFilterFree(virNWFilterPtr nwfilter) +{ + if (!nwfilter) + return; + + vshSaveLibvirtHelperError(); + virNWFilterFree(nwfilter); /* sc_prohibit_obj_free_apis_in_virsh */ +} + + void virshSecretFree(virSecretPtr secret) { diff --git a/tools/virsh-util.h b/tools/virsh-util.h index 06e311b21a..065055ddb1 100644 --- a/tools/virsh-util.h +++ b/tools/virsh-util.h @@ -69,6 +69,11 @@ void virshNodeDeviceFree(virNodeDevicePtr device); G_DEFINE_AUTOPTR_CLEANUP_FUNC(virshNodeDevice, virshNodeDeviceFree); =20 +typedef virNWFilter virshNWFilter; +void +virshNWFilterFree(virNWFilterPtr nwfilter); +G_DEFINE_AUTOPTR_CLEANUP_FUNC(virshNWFilter, virshNWFilterFree); + typedef virSecret virshSecret; void virshSecretFree(virSecretPtr secret); --=20 2.32.0 From nobody Sun May 19 10:57:28 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 170.10.133.124 as permitted sender) client-ip=170.10.133.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.133.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=1632719299; cv=none; d=zohomail.com; s=zohoarc; b=ROpsQHRRhXWLL2k12wXzQnPtDPDCPy6jPzbsA/eofwTd5+IPUFFdIxIXm9gV+SO1CukedoovcSUvd/WxXDlaD4tikRx1oOre0j+/93FCrdIt96qQAH7WPS8cUS1YrpbonxUSoxKdtprXWLwzttNFBUuOFKrizppulGsaXUsqxYs= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1632719299; 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=J3Lf2dSD+pectOd8UmJMfcGWF/loMim3e+ChQQhvFBs=; b=X2Kyr7KI/AfH5j4D99HlHyOIvqcrKzSkD3HEjjOlb2wfFno5ip0v2sMcGD+2VCm5uOvo22gk4K/Xq9zA4zObfieeXJzMBvsaF5tno7cAyVf4KDUR0aoIF8eFItMMxV+6M4qwVYnmHeiqVp1HJ3YpXNZj/+a8RJIG0cjgrGyQqEs= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 170.10.133.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.133.124]) by mx.zohomail.com with SMTPS id 1632719299020636.6905479010439; Sun, 26 Sep 2021 22:08:19 -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-496-Zj6QCacFNdWAJuI3cz2vIg-1; Mon, 27 Sep 2021 01:08:16 -0400 Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.phx2.redhat.com [10.5.11.14]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id A6C5E36300; Mon, 27 Sep 2021 05:08:09 +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 8508A17B5B; Mon, 27 Sep 2021 05:08:09 +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 210E84EA39; Mon, 27 Sep 2021 05:08:09 +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 18R58614004254 for ; Mon, 27 Sep 2021 01:08:06 -0400 Received: by smtp.corp.redhat.com (Postfix) id 7DB6D189C4; Mon, 27 Sep 2021 05:08:06 +0000 (UTC) Received: from localhost.localdomain (unknown [10.40.192.53]) by smtp.corp.redhat.com (Postfix) with ESMTP id E538B652A1 for ; Mon, 27 Sep 2021 05:08:05 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1632719298; 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=J3Lf2dSD+pectOd8UmJMfcGWF/loMim3e+ChQQhvFBs=; b=Nvj3j/H+lq7wLHwpA22Pritu9+dZqELM12eoQszXZPruOV2aO7xzpM5Prrk2160MMn2TEM AoKjHFZeTwismhUnHp9qsWP7U5Lac3XrEkjNIMk2Q6K5sRyjzGCz4wOIgJXlbVoxLlzecU Hw+vNyF0K/s5xv41++ckLyFkrKUHdpk= X-MC-Unique: Zj6QCacFNdWAJuI3cz2vIg-1 From: Michal Privoznik To: libvir-list@redhat.com Subject: [PATCH 8/8] virsh: Add wrapper for virStreamFree Date: Mon, 27 Sep 2021 07:07:50 +0200 Message-Id: <1549ea00db7252709bdcec1425ca24739fe8f049.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.14 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: 1632719300827100003 Content-Type: text/plain; charset="utf-8" Similarly to virshDomainFree add a wrapper for the snapshot object freeing function. Signed-off-by: Michal Privoznik Acked-by: Jonathon Jongsma --- build-aux/syntax-check.mk | 2 +- tools/virsh-console.c | 8 ++++---- tools/virsh-domain.c | 4 +--- tools/virsh-util.c | 12 ++++++++++++ tools/virsh-util.h | 5 +++++ tools/virsh-volume.c | 8 ++------ 6 files changed, 25 insertions(+), 14 deletions(-) diff --git a/build-aux/syntax-check.mk b/build-aux/syntax-check.mk index 5daf5afcd0..cb12b64532 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|Network|NodeDevice|NWF= ilter|Secret|StoragePool|StorageVol)Free\b' \ + @prohibit=3D'\bvir(Domain|DomainSnapshot|Interface|Network|NodeDevice|NWF= ilter|Secret|StoragePool|StorageVol|Stream)Free\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-console.c b/tools/virsh-console.c index 449619c95f..67ee608706 100644 --- a/tools/virsh-console.c +++ b/tools/virsh-console.c @@ -33,6 +33,7 @@ # include "internal.h" # include "virsh.h" # include "virsh-console.h" +# include "virsh-util.h" # include "virlog.h" # include "virfile.h" # include "viralloc.h" @@ -117,8 +118,8 @@ virConsoleShutdown(virConsole *con, virReportError(VIR_ERR_INTERNAL_ERROR, "%s", _("cannot terminate console stream")); } - virStreamFree(con->st); - con->st =3D NULL; + + g_clear_pointer(&con->st, virshStreamFree); } VIR_FREE(con->streamToTerminal.data); VIR_FREE(con->terminalToStream.data); @@ -140,8 +141,7 @@ virConsoleDispose(void *obj) { virConsole *con =3D obj; =20 - if (con->st) - virStreamFree(con->st); + virshStreamFree(con->st); =20 virCondDestroy(&con->cond); virResetError(&con->error); diff --git a/tools/virsh-domain.c b/tools/virsh-domain.c index b1943b3875..0d4f7cc407 100644 --- a/tools/virsh-domain.c +++ b/tools/virsh-domain.c @@ -5540,7 +5540,7 @@ cmdScreenshot(vshControl *ctl, const vshCmd *cmd) const char *name =3D NULL; char *file =3D NULL; int fd =3D -1; - virStreamPtr st =3D NULL; + g_autoptr(virshStream) st =3D NULL; unsigned int screen =3D 0; unsigned int flags =3D 0; /* currently unused */ bool ret =3D false; @@ -5610,8 +5610,6 @@ cmdScreenshot(vshControl *ctl, const vshCmd *cmd) unlink(file); if (generated) VIR_FREE(file); - if (st) - virStreamFree(st); VIR_FORCE_CLOSE(fd); VIR_FREE(mime); return ret; diff --git a/tools/virsh-util.c b/tools/virsh-util.c index fc2839d8fc..8fb617fa3c 100644 --- a/tools/virsh-util.c +++ b/tools/virsh-util.c @@ -362,6 +362,18 @@ virshStorageVolFree(virStorageVolPtr vol) } =20 =20 + +void +virshStreamFree(virStreamPtr stream) +{ + if (!stream) + return; + + vshSaveLibvirtHelperError(); + virStreamFree(stream); /* 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 065055ddb1..838935d5e8 100644 --- a/tools/virsh-util.h +++ b/tools/virsh-util.h @@ -89,6 +89,11 @@ void virshStorageVolFree(virStorageVolPtr vol); G_DEFINE_AUTOPTR_CLEANUP_FUNC(virshStorageVol, virshStorageVolFree); =20 +typedef virStream virshStream; +void +virshStreamFree(virStreamPtr stream); +G_DEFINE_AUTOPTR_CLEANUP_FUNC(virshStream, virshStreamFree); + int virshDomainState(vshControl *ctl, virDomainPtr dom, diff --git a/tools/virsh-volume.c b/tools/virsh-volume.c index b896ebbbf9..70b6eac687 100644 --- a/tools/virsh-volume.c +++ b/tools/virsh-volume.c @@ -656,7 +656,7 @@ cmdVolUpload(vshControl *ctl, const vshCmd *cmd) g_autoptr(virshStorageVol) vol =3D NULL; bool ret =3D false; int fd =3D -1; - virStreamPtr st =3D NULL; + g_autoptr(virshStream) st =3D NULL; const char *name =3D NULL; unsigned long long offset =3D 0, length =3D 0; virshControl *priv =3D ctl->privData; @@ -731,8 +731,6 @@ cmdVolUpload(vshControl *ctl, const vshCmd *cmd) ret =3D true; =20 cleanup: - if (st) - virStreamFree(st); VIR_FORCE_CLOSE(fd); return ret; } @@ -776,7 +774,7 @@ cmdVolDownload(vshControl *ctl, const vshCmd *cmd) g_autoptr(virshStorageVol) vol =3D NULL; bool ret =3D false; int fd =3D -1; - virStreamPtr st =3D NULL; + g_autoptr(virshStream) st =3D NULL; const char *name =3D NULL; unsigned long long offset =3D 0, length =3D 0; bool created =3D false; @@ -851,8 +849,6 @@ cmdVolDownload(vshControl *ctl, const vshCmd *cmd) VIR_FORCE_CLOSE(fd); if (!ret && created) unlink(file); - if (st) - virStreamFree(st); return ret; } =20 --=20 2.32.0