]> git.ipfire.org Git - thirdparty/libvirt.git/commitdiff
virStorageFileBackendGlusterInit: Refactor cleanup
authorPeter Krempa <pkrempa@redhat.com>
Wed, 25 Jun 2025 07:51:56 +0000 (09:51 +0200)
committerPeter Krempa <pkrempa@redhat.com>
Wed, 23 Jul 2025 12:47:24 +0000 (14:47 +0200)
Automatically free 'priv' and call 'glfs_fini()' directly from the two
error paths.

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

index df4df0f128a57ec076ca1bb5839dbac2948b4cc4..abb1c473097f5c8bbea926faea2207b6deab6b9c 100644 (file)
@@ -97,7 +97,7 @@ static int
 virStorageFileBackendGlusterInit(virStorageSource *src)
 {
     virStorageDriverData *drv = src->drv;
-    virStorageFileBackendGlusterPriv *priv = NULL;
+    g_autofree virStorageFileBackendGlusterPriv *priv = NULL;
     size_t i;
 
     if (!src->volume) {
@@ -117,31 +117,27 @@ virStorageFileBackendGlusterInit(virStorageSource *src)
     if (!(priv->vol = glfs_new(src->volume))) {
         virReportError(VIR_ERR_OPERATION_FAILED,
                        _("failed to create glfs object for '%1$s'"), src->volume);
-        goto error;
+        return -1;
     }
 
     for (i = 0; i < src->nhosts; i++) {
-        if (virStorageFileBackendGlusterInitServer(priv, src->hosts + i) < 0)
-            goto error;
+        if (virStorageFileBackendGlusterInitServer(priv, src->hosts + i) < 0) {
+            glfs_fini(priv->vol);
+            return -1;
+        }
     }
 
     if (glfs_init(priv->vol) < 0) {
         virReportSystemError(errno,
                              _("failed to initialize gluster connection (src=%1$p priv=%2$p)"),
                              src, priv);
-        goto error;
+        glfs_fini(priv->vol);
+        return -1;
     }
 
-    drv->priv = priv;
+    drv->priv = g_steal_pointer(&priv);
 
     return 0;
-
- error:
-    if (priv->vol)
-        glfs_fini(priv->vol);
-    VIR_FREE(priv);
-
-    return -1;
 }