]> git.ipfire.org Git - thirdparty/libvirt.git/commitdiff
tools: virsh: use automatic cleanup for char **
authorJán Tomko <jtomko@redhat.com>
Wed, 11 Aug 2021 13:45:02 +0000 (15:45 +0200)
committerJán Tomko <jtomko@redhat.com>
Mon, 16 Aug 2021 11:10:34 +0000 (13:10 +0200)
Signed-off-by: Ján Tomko <jtomko@redhat.com>
Reviewed-by: Martin Kletzander <mkletzan@redhat.com>
tools/virsh-domain.c
tools/virsh-host.c
tools/virsh-nodedev.c
tools/virsh-pool.c

index 542e2a1736c253e6d95aafe41fe1e9dae96dbb97..0636bbfa313f68e219abdc91ba224467ddb92573 100644 (file)
@@ -4002,7 +4002,7 @@ cmdStartGetFDs(vshControl *ctl,
                int **fdsret)
 {
     const char *fdopt;
-    char **fdlist = NULL;
+    g_auto(GStrv) fdlist = NULL;
     int *fds = NULL;
     size_t nfds = 0;
     size_t i;
@@ -4028,14 +4028,11 @@ cmdStartGetFDs(vshControl *ctl,
         fds[nfds - 1] = fd;
     }
 
-    g_strfreev(fdlist);
-
     *fdsret = fds;
     *nfdsret = nfds;
     return 0;
 
  error:
-    g_strfreev(fdlist);
     VIR_FREE(fds);
     return -1;
 }
@@ -5859,7 +5856,7 @@ cmdShutdown(vshControl *ctl, const vshCmd *cmd)
     const char *mode = NULL;
     int flags = 0;
     int rv;
-    char **modes = NULL;
+    g_auto(GStrv) modes = NULL;
     char **tmp;
 
     if (vshCommandOptStringReq(ctl, cmd, "mode", &mode) < 0)
@@ -5908,7 +5905,6 @@ cmdShutdown(vshControl *ctl, const vshCmd *cmd)
 
     ret = true;
  cleanup:
-    g_strfreev(modes);
     return ret;
 }
 
@@ -5943,7 +5939,7 @@ cmdReboot(vshControl *ctl, const vshCmd *cmd)
     const char *name;
     const char *mode = NULL;
     int flags = 0;
-    char **modes = NULL;
+    g_auto(GStrv) modes = NULL;
     char **tmp;
 
     if (vshCommandOptStringReq(ctl, cmd, "mode", &mode) < 0)
@@ -5988,7 +5984,6 @@ cmdReboot(vshControl *ctl, const vshCmd *cmd)
 
     ret = true;
  cleanup:
-    g_strfreev(modes);
     return ret;
 }
 
index a07f5adbfaa4fc00bf589f094d342ecec4dfc4f9..df1fe49e09e946861e2063a821d10ab0dc0e0a73 100644 (file)
@@ -1301,7 +1301,7 @@ cmdCPUBaseline(vshControl *ctl, const vshCmd *cmd)
     const char *from = NULL;
     bool ret = false;
     char *result = NULL;
-    char **list = NULL;
+    g_auto(GStrv) list = NULL;
     unsigned int flags = 0;
     virshControl *priv = ctl->privData;
 
@@ -1326,7 +1326,6 @@ cmdCPUBaseline(vshControl *ctl, const vshCmd *cmd)
     }
 
     VIR_FREE(result);
-    g_strfreev(list);
     return ret;
 }
 
index 5b1afe4601246986048c9c7b8c778b790d83116e..c6c7d97d50b16b1d3c93f507019f349c71825c63 100644 (file)
@@ -115,7 +115,7 @@ static virNodeDevice*
 vshFindNodeDevice(vshControl *ctl, const char *value)
 {
     virNodeDevicePtr dev = NULL;
-    char **arr = NULL;
+    g_auto(GStrv) arr = NULL;
     int narr;
     virshControl *priv = ctl->privData;
 
@@ -140,7 +140,6 @@ vshFindNodeDevice(vshControl *ctl, const char *value)
     }
 
  cleanup:
-    g_strfreev(arr);
     return dev;
 }
 
@@ -409,7 +408,7 @@ cmdNodeListDevices(vshControl *ctl, const vshCmd *cmd G_GNUC_UNUSED)
     bool tree = vshCommandOptBool(cmd, "tree");
     bool ret = true;
     unsigned int flags = 0;
-    char **caps = NULL;
+    g_auto(GStrv) caps = NULL;
     int ncaps = 0;
     struct virshNodeDeviceList *list = NULL;
     int cap_type = -1;
@@ -555,7 +554,6 @@ cmdNodeListDevices(vshControl *ctl, const vshCmd *cmd G_GNUC_UNUSED)
     }
 
  cleanup:
-    g_strfreev(caps);
     virshNodeDeviceListFree(list);
     return ret;
 }
index 5bce5cf06c058c8abe0af9eba94a6a5009113fae..03987770f645d3934a672c37dc95d25f456d673b 100644 (file)
@@ -1175,7 +1175,7 @@ cmdPoolList(vshControl *ctl, const vshCmd *cmd G_GNUC_UNUSED)
 
     if (type) {
         int poolType = -1;
-        char **poolTypes = NULL;
+        g_auto(GStrv) poolTypes = NULL;
         int npoolTypes = 0;
 
         if ((npoolTypes = vshStringToArray(type, &poolTypes)) < 0)
@@ -1184,7 +1184,6 @@ cmdPoolList(vshControl *ctl, const vshCmd *cmd G_GNUC_UNUSED)
         for (i = 0; i < npoolTypes; i++) {
             if ((poolType = virStoragePoolTypeFromString(poolTypes[i])) < 0) {
                 vshError(ctl, _("Invalid pool type '%s'"), poolTypes[i]);
-                g_strfreev(poolTypes);
                 return false;
             }
 
@@ -1235,7 +1234,6 @@ cmdPoolList(vshControl *ctl, const vshCmd *cmd G_GNUC_UNUSED)
                 break;
             }
         }
-        g_strfreev(poolTypes);
     }
 
     if (!(list = virshStoragePoolListCollect(ctl, flags)))