]> git.ipfire.org Git - thirdparty/libvirt.git/commitdiff
virStorageBackendLogicalParseVolExtents: Move 'extents' inside the loop
authorPeter Krempa <pkrempa@redhat.com>
Wed, 4 Aug 2021 10:18:38 +0000 (12:18 +0200)
committerPeter Krempa <pkrempa@redhat.com>
Fri, 6 Aug 2021 06:53:26 +0000 (08:53 +0200)
It's used only inside the loop filling the extents, move it there and
restructure the code so that 'extent.path' doesn't have to be freed.

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

index cffa2c88494d3100b4f724f6af6c529891d3df61..90e7c9e41da7f9c0bbb7b369b3007936fc6338dd 100644 (file)
@@ -128,11 +128,8 @@ virStorageBackendLogicalParseVolExtents(virStorageVolDef *vol,
     unsigned long long offset;
     unsigned long long size;
     unsigned long long length;
-    virStorageVolSourceExtent extent;
     g_autofree char *regex = NULL;
 
-    memset(&extent, 0, sizeof(extent));
-
     /* Assume 1 extent (the regex for 'devices' is "(\\S+)") and only
      * check the 'stripes' field if we have a striped, mirror, or one of
      * the raid (raid1, raid4, raid5*, raid6*, or raid10) segtypes in which
@@ -189,11 +186,12 @@ virStorageBackendLogicalParseVolExtents(virStorageVolDef *vol,
      * is the whole matched string.
      */
     for (i = 0; i < nextents; i++) {
-        size_t j;
         g_autofree char *offset_str = NULL;
+        virStorageVolSourceExtent extent;
+        size_t j = (i * 2) + 1;
+
+        memset(&extent, 0, sizeof(extent));
 
-        j = (i * 2) + 1;
-        extent.path = g_match_info_fetch(info, j);
         offset_str = g_match_info_fetch(info, j + 1);
 
         if (virStrToLong_ull(offset_str, NULL, 10, &offset) < 0) {
@@ -201,6 +199,8 @@ virStorageBackendLogicalParseVolExtents(virStorageVolDef *vol,
                            _("malformed volume extent offset value"));
             goto cleanup;
         }
+
+        extent.path = g_match_info_fetch(info, j);
         extent.start = offset * size;
         extent.end = (offset * size) + length;
 
@@ -210,7 +210,6 @@ virStorageBackendLogicalParseVolExtents(virStorageVolDef *vol,
     ret = 0;
 
  cleanup:
-    VIR_FREE(extent.path);
     return ret;
 }