mirror of
https://gitlab.com/libvirt/libvirt.git
synced 2025-03-07 17:28:15 +00:00
virLockManagerSanlockAddLease: Refactor cleanup
Use g_autofree and remove the 'cleanup' section and 'ret' variable. Signed-off-by: Peter Krempa <pkrempa@redhat.com> Reviewed-by: Daniel P. Berrangé <berrange@redhat.com>
This commit is contained in:
parent
add18b06c7
commit
30a42dcddc
@ -528,12 +528,11 @@ static int virLockManagerSanlockAddLease(virLockManagerPtr lock,
|
||||
bool shared)
|
||||
{
|
||||
virLockManagerSanlockPrivatePtr priv = lock->privateData;
|
||||
int ret = -1;
|
||||
struct sanlk_resource *res = NULL;
|
||||
g_autofree struct sanlk_resource *res = NULL;
|
||||
size_t i;
|
||||
|
||||
if (VIR_ALLOC_VAR(res, struct sanlk_disk, 1) < 0)
|
||||
goto cleanup;
|
||||
return -1;
|
||||
|
||||
res->flags = shared ? SANLK_RES_SHARED : 0;
|
||||
res->num_disks = 1;
|
||||
@ -541,7 +540,7 @@ static int virLockManagerSanlockAddLease(virLockManagerPtr lock,
|
||||
virReportError(VIR_ERR_INTERNAL_ERROR,
|
||||
_("Resource name '%s' exceeds %d characters"),
|
||||
name, SANLK_NAME_LEN);
|
||||
goto cleanup;
|
||||
return -1;
|
||||
}
|
||||
|
||||
for (i = 0; i < nparams; i++) {
|
||||
@ -550,7 +549,7 @@ static int virLockManagerSanlockAddLease(virLockManagerPtr lock,
|
||||
virReportError(VIR_ERR_INTERNAL_ERROR,
|
||||
_("Lease path '%s' exceeds %d characters"),
|
||||
params[i].value.str, SANLK_PATH_LEN);
|
||||
goto cleanup;
|
||||
return -1;
|
||||
}
|
||||
} else if (STREQ(params[i].key, "offset")) {
|
||||
res->disks[0].offset = params[i].value.ul;
|
||||
@ -559,20 +558,15 @@ static int virLockManagerSanlockAddLease(virLockManagerPtr lock,
|
||||
virReportError(VIR_ERR_INTERNAL_ERROR,
|
||||
_("Resource lockspace '%s' exceeds %d characters"),
|
||||
params[i].value.str, SANLK_NAME_LEN);
|
||||
goto cleanup;
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
priv->res_args[priv->res_count] = res;
|
||||
priv->res_args[priv->res_count] = g_steal_pointer(&res);
|
||||
priv->res_count++;
|
||||
|
||||
ret = 0;
|
||||
|
||||
cleanup:
|
||||
if (ret == -1)
|
||||
VIR_FREE(res);
|
||||
return ret;
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user