]> git.ipfire.org Git - thirdparty/libvirt.git/commitdiff
virsh: Add wrapper for virNWFilterFree
authorMichal Privoznik <mprivozn@redhat.com>
Sun, 26 Sep 2021 11:18:17 +0000 (13:18 +0200)
committerMichal Privoznik <mprivozn@redhat.com>
Wed, 6 Oct 2021 07:27:03 +0000 (09:27 +0200)
Similarly to virshDomainFree add a wrapper for the snapshot object
freeing function.

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
Acked-by: Jonathon Jongsma <jjongsma@redhat.com>
build-aux/syntax-check.mk
tools/virsh-completer-nwfilter.c
tools/virsh-nwfilter.c
tools/virsh-util.c
tools/virsh-util.h

index 6c230826bd810bfbf6efe025d083c63f53ea8349..5daf5afcd024f81e464ab8e9b879d88d6e2456c8 100644 (file)
@@ -868,7 +868,7 @@ sc_gettext_init:
          $(_sc_search_regexp)
 
 sc_prohibit_obj_free_apis_in_virsh:
-       @prohibit='\bvir(Domain|DomainSnapshot|Interface|Network|NodeDevice|Secret|StoragePool|StorageVol)Free\b' \
+       @prohibit='\bvir(Domain|DomainSnapshot|Interface|Network|NodeDevice|NWFilter|Secret|StoragePool|StorageVol)Free\b' \
        in_vc_files='virsh.*\.[ch]$$' \
        exclude='sc_prohibit_obj_free_apis_in_virsh' \
        halt='avoid using public virXXXFree in virsh, use virsh-prefixed wrappers instead' \
index 859f72f6e9c4ab13d40395e2fa37ab200f4caebf..9850dbba5d9eedc06672c16e561fcc0422fd4bd0 100644 (file)
@@ -21,6 +21,7 @@
 #include <config.h>
 
 #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 = g_steal_pointer(&tmp);
 
     for (i = 0; i < nnwfilters; i++)
-        virNWFilterFree(nwfilters[i]);
+        virshNWFilterFree(nwfilters[i]);
     g_free(nwfilters);
     return ret;
 }
index 33164f623fbe89fa5cb323f1d8f37d0a19b443de..09ceaf6ec91a26da5e35f8e69b44e4c4a39fb71f 100644 (file)
@@ -20,6 +20,7 @@
 
 #include <config.h>
 #include "virsh-nwfilter.h"
+#include "virsh-util.h"
 
 #include "internal.h"
 #include "viralloc.h"
@@ -91,7 +92,7 @@ static const vshCmdOptDef opts_nwfilter_define[] = {
 static bool
 cmdNWFilterDefine(vshControl *ctl, const vshCmd *cmd)
 {
-    virNWFilterPtr nwfilter;
+    g_autoptr(virshNWFilter) nwfilter = NULL;
     const char *from = NULL;
     bool ret = true;
     g_autofree char *buffer = NULL;
@@ -115,7 +116,6 @@ cmdNWFilterDefine(vshControl *ctl, const vshCmd *cmd)
     if (nwfilter != 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 = false;
@@ -149,7 +149,7 @@ static const vshCmdOptDef opts_nwfilter_undefine[] = {
 static bool
 cmdNWFilterUndefine(vshControl *ctl, const vshCmd *cmd)
 {
-    virNWFilterPtr nwfilter;
+    g_autoptr(virshNWFilter) nwfilter = NULL;
     bool ret = true;
     const char *name;
 
@@ -163,7 +163,6 @@ cmdNWFilterUndefine(vshControl *ctl, const vshCmd *cmd)
         ret = false;
     }
 
-    virNWFilterFree(nwfilter);
     return ret;
 }
 
@@ -193,7 +192,7 @@ static const vshCmdOptDef opts_nwfilter_dumpxml[] = {
 static bool
 cmdNWFilterDumpXML(vshControl *ctl, const vshCmd *cmd)
 {
-    virNWFilterPtr nwfilter;
+    g_autoptr(virshNWFilter) nwfilter = NULL;
     bool ret = true;
     g_autofree char *dump = NULL;
 
@@ -207,7 +206,6 @@ cmdNWFilterDumpXML(vshControl *ctl, const vshCmd *cmd)
         ret = false;
     }
 
-    virNWFilterFree(nwfilter);
     return ret;
 }
 
@@ -239,8 +237,7 @@ virshNWFilterListFree(struct virshNWFilterList *list)
 
     if (list && list->filters) {
         for (i = 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 = false;
-    virNWFilterPtr nwfilter = NULL;
-    virNWFilterPtr nwfilter_edited = NULL;
+    g_autoptr(virshNWFilter) nwfilter = NULL;
+    g_autoptr(virshNWFilter) nwfilter_edited = NULL;
     virshControl *priv = ctl->privData;
 
     nwfilter = virshCommandOptNWFilter(ctl, cmd, NULL);
@@ -445,11 +442,6 @@ cmdNWFilterEdit(vshControl *ctl, const vshCmd *cmd)
     ret = true;
 
  cleanup:
-    if (nwfilter)
-        virNWFilterFree(nwfilter);
-    if (nwfilter_edited)
-        virNWFilterFree(nwfilter_edited);
-
     return ret;
 }
 
index 5034f4773f658240c3fa588ae442e66149677377..fc2839d8fc000d497031884251d1db7562fb2cda 100644 (file)
@@ -318,6 +318,17 @@ virshNodeDeviceFree(virNodeDevicePtr device)
 }
 
 
+void
+virshNWFilterFree(virNWFilterPtr nwfilter)
+{
+    if (!nwfilter)
+        return;
+
+    vshSaveLibvirtHelperError();
+    virNWFilterFree(nwfilter); /* sc_prohibit_obj_free_apis_in_virsh */
+}
+
+
 void
 virshSecretFree(virSecretPtr secret)
 {
index 06e311b21a216596e60539642fbe2e8002884703..065055ddb141996aaafc8622289e4b1a432dfd9b 100644 (file)
@@ -69,6 +69,11 @@ void
 virshNodeDeviceFree(virNodeDevicePtr device);
 G_DEFINE_AUTOPTR_CLEANUP_FUNC(virshNodeDevice, virshNodeDeviceFree);
 
+typedef virNWFilter virshNWFilter;
+void
+virshNWFilterFree(virNWFilterPtr nwfilter);
+G_DEFINE_AUTOPTR_CLEANUP_FUNC(virshNWFilter, virshNWFilterFree);
+
 typedef virSecret virshSecret;
 void
 virshSecretFree(virSecretPtr secret);