virsh: cmdDetachDisk: Refactor cleanup

Use automatic pointer freeing for the 'disk_node' variable and remove
the 'cleanup' label and 'functionReturn' variable.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
This commit is contained in:
Peter Krempa 2022-12-02 10:14:09 +01:00
parent e9b7f06140
commit be9560070b

View File

@ -12894,8 +12894,7 @@ cmdDetachDisk(vshControl *ctl, const vshCmd *cmd)
const char *target = NULL; const char *target = NULL;
g_autofree char *doc = NULL; g_autofree char *doc = NULL;
int ret; int ret;
bool functionReturn = false; g_autoptr(xmlNode) disk_node = NULL;
xmlNodePtr disk_node = NULL;
bool current = vshCommandOptBool(cmd, "current"); bool current = vshCommandOptBool(cmd, "current");
bool config = vshCommandOptBool(cmd, "config"); bool config = vshCommandOptBool(cmd, "config");
bool live = vshCommandOptBool(cmd, "live"); bool live = vshCommandOptBool(cmd, "live");
@ -12916,7 +12915,7 @@ cmdDetachDisk(vshControl *ctl, const vshCmd *cmd)
return false; return false;
if (vshCommandOptStringReq(ctl, cmd, "target", &target) < 0) if (vshCommandOptStringReq(ctl, cmd, "target", &target) < 0)
goto cleanup; return false;
if (flags == VIR_DOMAIN_AFFECT_CONFIG) if (flags == VIR_DOMAIN_AFFECT_CONFIG)
doc = virDomainGetXMLDesc(dom, VIR_DOMAIN_XML_INACTIVE); doc = virDomainGetXMLDesc(dom, VIR_DOMAIN_XML_INACTIVE);
@ -12924,24 +12923,23 @@ cmdDetachDisk(vshControl *ctl, const vshCmd *cmd)
doc = virDomainGetXMLDesc(dom, 0); doc = virDomainGetXMLDesc(dom, 0);
if (!doc) if (!doc)
goto cleanup; return false;
if (persistent && if (persistent &&
virDomainIsActive(dom) == 1) virDomainIsActive(dom) == 1)
flags |= VIR_DOMAIN_AFFECT_LIVE; flags |= VIR_DOMAIN_AFFECT_LIVE;
if (!(disk_node = virshFindDisk(doc, target, VIRSH_FIND_DISK_NORMAL))) if (!(disk_node = virshFindDisk(doc, target, VIRSH_FIND_DISK_NORMAL)))
goto cleanup; return false;
if (!(disk_xml = virXMLNodeToString(NULL, disk_node))) { if (!(disk_xml = virXMLNodeToString(NULL, disk_node))) {
vshSaveLibvirtError(); vshSaveLibvirtError();
goto cleanup; return false;
} }
if (vshCommandOptBool(cmd, "print-xml")) { if (vshCommandOptBool(cmd, "print-xml")) {
vshPrint(ctl, "%s", disk_xml); vshPrint(ctl, "%s", disk_xml);
functionReturn = true; return true;
goto cleanup;
} }
if (flags != 0 || current) if (flags != 0 || current)
@ -12951,15 +12949,11 @@ cmdDetachDisk(vshControl *ctl, const vshCmd *cmd)
if (ret != 0) { if (ret != 0) {
vshError(ctl, "%s", _("Failed to detach disk")); vshError(ctl, "%s", _("Failed to detach disk"));
goto cleanup; return false;
} }
vshPrintExtra(ctl, "%s", _("Disk detached successfully\n")); vshPrintExtra(ctl, "%s", _("Disk detached successfully\n"));
functionReturn = true; return true;
cleanup:
xmlFreeNode(disk_node);
return functionReturn;
} }
/* /*