]> git.ipfire.org Git - thirdparty/libvirt.git/commitdiff
virStorageBackendRBDGetVolNames: Refactor cleanup in 'rbd_list' version
authorPeter Krempa <pkrempa@redhat.com>
Mon, 14 Jun 2021 14:44:19 +0000 (16:44 +0200)
committerPeter Krempa <pkrempa@redhat.com>
Tue, 15 Jun 2021 14:58:23 +0000 (16:58 +0200)
Use automatic memory freeing for the string list so that we can remove
the cleanup section.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
src/storage/storage_backend_rbd.c

index 371ebfaf1bdd0f3de57cbc17097e480e009403d9..a4e8115dc452d557818441791285b539fa2fb922 100644 (file)
@@ -611,7 +611,7 @@ virStorageBackendRBDGetVolNames(virStorageBackendRBDState *ptr)
 static char **
 virStorageBackendRBDGetVolNames(virStorageBackendRBDState *ptr)
 {
-    char **names = NULL;
+    g_auto(GStrv) names = NULL;
     size_t nnames = 0;
     int rc;
     size_t max_size = 1024;
@@ -626,7 +626,7 @@ virStorageBackendRBDGetVolNames(virStorageBackendRBDState *ptr)
             break;
         if (rc != -ERANGE) {
             virReportSystemError(errno, "%s", _("Unable to list RBD images"));
-            goto error;
+            return NULL;
         }
         VIR_FREE(namebuf);
     }
@@ -640,18 +640,14 @@ virStorageBackendRBDGetVolNames(virStorageBackendRBDState *ptr)
         namedup = g_strdup(name);
 
         if (VIR_APPEND_ELEMENT(names, nnames, namedup) < 0)
-            goto error;
+            return NULL;
 
         name += strlen(name) + 1;
     }
 
     VIR_EXPAND_N(names, nnames, 1);
 
-    return names;
-
- error:
-    virStringListFreeCount(names, nnames);
-    return NULL;
+    return g_steal_pointer(&names);
 }
 #endif /* ! WITH_RBD_LIST2 */