From nobody Tue Feb 10 04:08:00 2026 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 --- 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