]> git.ipfire.org Git - thirdparty/libvirt.git/commitdiff
virStorageBackendSheepdogAddVolume: Clean up memory handling
authorPeter Krempa <pkrempa@redhat.com>
Fri, 5 Feb 2021 16:03:14 +0000 (17:03 +0100)
committerPeter Krempa <pkrempa@redhat.com>
Thu, 11 Feb 2021 16:05:33 +0000 (17:05 +0100)
'cells' can be pushed into the loop removing the need for manual
cleanup, the check whether 'line' is NULL inside of the loop is always
false since the loop checks it right before and 'line' variable is
unnecessary.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
src/storage/storage_backend_sheepdog.c

index c5b7c568dd12a9cec203b971f7dd23db1b0d2867..178cfbae116fe4bfb5845eafeebe6d13341b84cb 100644 (file)
@@ -140,7 +140,6 @@ virStorageBackendSheepdogRefreshAllVol(virStoragePoolObjPtr pool)
     size_t i;
     g_autofree char *output = NULL;
     g_auto(GStrv) lines = NULL;
-    g_auto(GStrv) cells = NULL;
     g_autoptr(virCommand) cmd = NULL;
 
     cmd = virCommandNewArgList(SHEEPDOGCLI, "vdi", "list", "-r", NULL);
@@ -154,20 +153,15 @@ virStorageBackendSheepdogRefreshAllVol(virStoragePoolObjPtr pool)
         return -1;
 
     for (i = 0; lines[i]; i++) {
-        const char *line = lines[i];
-        if (line == NULL)
-            break;
+        g_auto(GStrv) cells = NULL;
 
-        cells = virStringSplit(line, " ", 0);
+        cells = virStringSplit(lines[i], " ", 0);
 
         if (cells != NULL &&
             virStringListLength((const char * const *)cells) > 2) {
             if (virStorageBackendSheepdogAddVolume(pool, cells[1]) < 0)
                 return -1;
         }
-
-        g_strfreev(cells);
-        cells = NULL;
     }
 
     return 0;