From: Peter Krempa <pkre...@redhat.com> Automatically free 'priv' and call 'glfs_fini()' directly from the two error paths.
Signed-off-by: Peter Krempa <pkre...@redhat.com> --- .../storage_file_backend_gluster.c | 22 ++++++++----------- 1 file changed, 9 insertions(+), 13 deletions(-) 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; } -- 2.49.0