]> git.ipfire.org Git - thirdparty/libvirt.git/commitdiff
virsh: Add wrapper for virStreamFree
authorMichal Privoznik <mprivozn@redhat.com>
Sun, 26 Sep 2021 11:27:26 +0000 (13:27 +0200)
committerMichal Privoznik <mprivozn@redhat.com>
Wed, 6 Oct 2021 07:27:43 +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-console.c
tools/virsh-domain.c
tools/virsh-util.c
tools/virsh-util.h
tools/virsh-volume.c

index 5daf5afcd024f81e464ab8e9b879d88d6e2456c8..cb12b645325ef90e8e4c42080b17b1365ec6c6ab 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|NWFilter|Secret|StoragePool|StorageVol)Free\b' \
+       @prohibit='\bvir(Domain|DomainSnapshot|Interface|Network|NodeDevice|NWFilter|Secret|StoragePool|StorageVol|Stream)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 449619c95f3218435a6fd1522414287d54ce2dfe..67ee60870695e66e58d714cd1e65e7d12b934cb2 100644 (file)
@@ -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 = 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 = obj;
 
-    if (con->st)
-        virStreamFree(con->st);
+    virshStreamFree(con->st);
 
     virCondDestroy(&con->cond);
     virResetError(&con->error);
index 5b145d325747a676fa6f916e48ab59db4288a33b..db3f1b41c1fe79a913ed859593957be5ace306a1 100644 (file)
@@ -5540,7 +5540,7 @@ cmdScreenshot(vshControl *ctl, const vshCmd *cmd)
     const char *name = NULL;
     char *file = NULL;
     int fd = -1;
-    virStreamPtr st = NULL;
+    g_autoptr(virshStream) st = NULL;
     unsigned int screen = 0;
     unsigned int flags = 0; /* currently unused */
     bool ret = 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;
index fc2839d8fc000d497031884251d1db7562fb2cda..8fb617fa3c2aabdc8ef3b1d973c002c8efe9d393 100644 (file)
@@ -362,6 +362,18 @@ virshStorageVolFree(virStorageVolPtr vol)
 }
 
 
+
+void
+virshStreamFree(virStreamPtr stream)
+{
+    if (!stream)
+        return;
+
+    vshSaveLibvirtHelperError();
+    virStreamFree(stream); /* sc_prohibit_obj_free_apis_in_virsh */
+}
+
+
 int
 virshDomainGetXMLFromDom(vshControl *ctl,
                          virDomainPtr dom,
index 065055ddb141996aaafc8622289e4b1a432dfd9b..838935d5e82413837b5916e88383458f52d3871c 100644 (file)
@@ -89,6 +89,11 @@ void
 virshStorageVolFree(virStorageVolPtr vol);
 G_DEFINE_AUTOPTR_CLEANUP_FUNC(virshStorageVol, virshStorageVolFree);
 
+typedef virStream virshStream;
+void
+virshStreamFree(virStreamPtr stream);
+G_DEFINE_AUTOPTR_CLEANUP_FUNC(virshStream, virshStreamFree);
+
 int
 virshDomainState(vshControl *ctl,
                  virDomainPtr dom,
index b896ebbbf9518700d28a806c2e80448d1de12883..70b6eac687baf6501df0f4e5f29122a7b4c92501 100644 (file)
@@ -656,7 +656,7 @@ cmdVolUpload(vshControl *ctl, const vshCmd *cmd)
     g_autoptr(virshStorageVol) vol = NULL;
     bool ret = false;
     int fd = -1;
-    virStreamPtr st = NULL;
+    g_autoptr(virshStream) st = NULL;
     const char *name = NULL;
     unsigned long long offset = 0, length = 0;
     virshControl *priv = ctl->privData;
@@ -731,8 +731,6 @@ cmdVolUpload(vshControl *ctl, const vshCmd *cmd)
     ret = true;
 
  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 = NULL;
     bool ret = false;
     int fd = -1;
-    virStreamPtr st = NULL;
+    g_autoptr(virshStream) st = NULL;
     const char *name = NULL;
     unsigned long long offset = 0, length = 0;
     bool created = 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;
 }