From: Peter Krempa Date: Wed, 25 Jun 2025 07:51:56 +0000 (+0200) Subject: virStorageFileBackendGlusterInit: Refactor cleanup X-Git-Tag: v11.6.0-rc1~39 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=0723e066d92d28f43d7b1f51e611f0bc1ebf6c15;p=thirdparty%2Flibvirt.git virStorageFileBackendGlusterInit: Refactor cleanup Automatically free 'priv' and call 'glfs_fini()' directly from the two error paths. Signed-off-by: Peter Krempa Reviewed-by: Michal Privoznik --- diff --git a/src/storage_file/storage_file_backend_gluster.c b/src/storage_file/storage_file_backend_gluster.c index df4df0f128..abb1c47309 100644 --- a/src/storage_file/storage_file_backend_gluster.c +++ b/src/storage_file/storage_file_backend_gluster.c @@ -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; }