render / rpms / libvirt

Forked from rpms/libvirt 9 months ago
Clone
Blob Blame History Raw
From dce266130a7eef93d3f76940929cc92e1316b0a0 Mon Sep 17 00:00:00 2001
Message-Id: <dce266130a7eef93d3f76940929cc92e1316b0a0@dist-git>
From: Michal Privoznik <mprivozn@redhat.com>
Date: Mon, 8 Mar 2021 12:57:30 +0100
Subject: [PATCH] virDevMapperGetTargetsImpl: Use VIR_AUTOSTRINGLIST
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

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>
(cherry picked from commit b8ebbe05451fde7ce541564f73437a29ffd5db0d)

Conflicts:
- src/util/virdevmapper.c: Another Glib conflict, but
  fortunately, this time it's only in the context - the cherry
  picked commit uses g_steal_pointer() because of
  a3931b4996e46db409ad031e0230a507fb303287
  but the old code still uses VIR_STEAL_PTR().

Resolves: https://bugzilla.redhat.com/show_bug.cgi?id=1933557
Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
Message-Id: <c67e2ea85bd93ce5bb2ed136858f66d983403e1b.1615203117.git.mprivozn@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
---
 src/util/virdevmapper.c | 16 +++-------------
 1 file changed, 3 insertions(+), 13 deletions(-)

diff --git a/src/util/virdevmapper.c b/src/util/virdevmapper.c
index 6aee00112c..50d12ea0f1 100644
--- a/src/util/virdevmapper.c
+++ b/src/util/virdevmapper.c
@@ -72,8 +72,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;
 
@@ -139,28 +138,19 @@ virDevMapperGetTargetsImpl(const char *path,
             goto cleanup;
     }
 
-    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;
-
     VIR_STEAL_PTR(*devPaths_ret, devPaths);
     ret = 0;
  cleanup:
-    virStringListFree(recursiveDevPaths);
-    virStringListFree(devPaths);
     dm_task_destroy(dmt);
     return ret;
 }
-- 
2.31.0