mirror of
https://gitlab.com/libvirt/libvirt.git
synced 2025-03-07 17:28:15 +00:00
util: file: use VIR_AUTOPTR for aggregate types
By making use of GNU C's cleanup attribute handled by the VIR_AUTOPTR macro for declaring aggregate pointer variables, majority of the calls to *Free functions can be dropped, which in turn leads to getting rid of most of our cleanup sections. Signed-off-by: Sukrit Bhatnagar <skrtbhtngr@gmail.com> Reviewed-by: Erik Skultety <eskultet@redhat.com>
This commit is contained in:
parent
69b937f035
commit
fbd1f5b486
@ -888,20 +888,19 @@ int virFileNBDDeviceAssociate(const char *file,
|
|||||||
{
|
{
|
||||||
VIR_AUTOFREE(char *) nbddev = NULL;
|
VIR_AUTOFREE(char *) nbddev = NULL;
|
||||||
VIR_AUTOFREE(char *) qemunbd = NULL;
|
VIR_AUTOFREE(char *) qemunbd = NULL;
|
||||||
virCommandPtr cmd = NULL;
|
VIR_AUTOPTR(virCommand) cmd = NULL;
|
||||||
int ret = -1;
|
|
||||||
const char *fmtstr = NULL;
|
const char *fmtstr = NULL;
|
||||||
|
|
||||||
if (!virFileNBDLoadDriver())
|
if (!virFileNBDLoadDriver())
|
||||||
goto cleanup;
|
return -1;
|
||||||
|
|
||||||
if (!(nbddev = virFileNBDDeviceFindUnused()))
|
if (!(nbddev = virFileNBDDeviceFindUnused()))
|
||||||
goto cleanup;
|
return -1;
|
||||||
|
|
||||||
if (!(qemunbd = virFindFileInPath("qemu-nbd"))) {
|
if (!(qemunbd = virFindFileInPath("qemu-nbd"))) {
|
||||||
virReportSystemError(ENOENT, "%s",
|
virReportSystemError(ENOENT, "%s",
|
||||||
_("Unable to find 'qemu-nbd' binary in $PATH"));
|
_("Unable to find 'qemu-nbd' binary in $PATH"));
|
||||||
goto cleanup;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (fmt > 0)
|
if (fmt > 0)
|
||||||
@ -926,17 +925,14 @@ int virFileNBDDeviceAssociate(const char *file,
|
|||||||
/* qemu-nbd will daemonize itself */
|
/* qemu-nbd will daemonize itself */
|
||||||
|
|
||||||
if (virCommandRun(cmd, NULL) < 0)
|
if (virCommandRun(cmd, NULL) < 0)
|
||||||
goto cleanup;
|
return -1;
|
||||||
|
|
||||||
VIR_DEBUG("Associated NBD device %s with file %s and format %s",
|
VIR_DEBUG("Associated NBD device %s with file %s and format %s",
|
||||||
nbddev, file, fmtstr);
|
nbddev, file, fmtstr);
|
||||||
*dev = nbddev;
|
*dev = nbddev;
|
||||||
nbddev = NULL;
|
nbddev = NULL;
|
||||||
ret = 0;
|
|
||||||
|
|
||||||
cleanup:
|
return 0;
|
||||||
virCommandFree(cmd);
|
|
||||||
return ret;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#else /* __linux__ */
|
#else /* __linux__ */
|
||||||
|
Loading…
x
Reference in New Issue
Block a user