]> git.ipfire.org Git - thirdparty/libvirt.git/commitdiff
virDevMapperGetTargetsImpl: Use VIR_AUTOSTRINGLIST
authorMichal Privoznik <mprivozn@redhat.com>
Fri, 24 Jul 2020 07:40:04 +0000 (09:40 +0200)
committerMichal Privoznik <mprivozn@redhat.com>
Sat, 25 Jul 2020 09:14:39 +0000 (11:14 +0200)
Since we have VIR_AUTOSTRINGLIST we can use it to free string
lists used in the function automatically.

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
Reviewed-by: Daniel P. Berrangé <berrange@redhat.com>
src/util/virdevmapper.c

index 118dc82e949e2c61f499d1f7e8a3fcfc955d819a..44c4731fb49ef50a67bfbe640085a3a905ff108b 100644 (file)
@@ -67,8 +67,7 @@ virDevMapperGetTargetsImpl(const char *path,
     struct dm_task *dmt = NULL;
     struct dm_deps *deps;
     struct dm_info info;
-    char **devPaths = NULL;
-    char **recursiveDevPaths = NULL;
+    VIR_AUTOSTRINGLIST devPaths = NULL;
     size_t i;
     int ret = -1;
 
@@ -133,28 +132,19 @@ virDevMapperGetTargetsImpl(const char *path,
                                       minor(deps->device[i]));
     }
 
-    recursiveDevPaths = NULL;
     for (i = 0; i < deps->count; i++) {
-        char **tmpPaths;
+        VIR_AUTOSTRINGLIST tmpPaths = NULL;
 
         if (virDevMapperGetTargetsImpl(devPaths[i], &tmpPaths, ttl - 1) < 0)
             goto cleanup;
 
-        if (tmpPaths &&
-            virStringListMerge(&recursiveDevPaths, &tmpPaths) < 0) {
-            virStringListFree(tmpPaths);
+        if (virStringListMerge(&devPaths, &tmpPaths) < 0)
             goto cleanup;
-        }
     }
 
-    if (virStringListMerge(&devPaths, &recursiveDevPaths) < 0)
-        goto cleanup;
-
     *devPaths_ret = g_steal_pointer(&devPaths);
     ret = 0;
  cleanup:
-    virStringListFree(recursiveDevPaths);
-    virStringListFree(devPaths);
     dm_task_destroy(dmt);
     return ret;
 }