mirror of
https://gitlab.com/libvirt/libvirt.git
synced 2024-08-05 16:33:50 +00:00
virsh: Don't leak buffer if GetFDs fails in cmdCreate
Change the logic of the function to return false by default and move the freeing of the buffer to the cleanup section. https://bugzilla.redhat.com/show_bug.cgi?id=1067338
This commit is contained in:
parent
cfad607b23
commit
fe1b6e72d2
@ -6518,7 +6518,7 @@ cmdCreate(vshControl *ctl, const vshCmd *cmd)
|
|||||||
{
|
{
|
||||||
virDomainPtr dom;
|
virDomainPtr dom;
|
||||||
const char *from = NULL;
|
const char *from = NULL;
|
||||||
bool ret = true;
|
bool ret = false;
|
||||||
char *buffer;
|
char *buffer;
|
||||||
#ifndef WIN32
|
#ifndef WIN32
|
||||||
bool console = vshCommandOptBool(cmd, "console");
|
bool console = vshCommandOptBool(cmd, "console");
|
||||||
@ -6534,7 +6534,7 @@ cmdCreate(vshControl *ctl, const vshCmd *cmd)
|
|||||||
return false;
|
return false;
|
||||||
|
|
||||||
if (cmdStartGetFDs(ctl, cmd, &nfds, &fds) < 0)
|
if (cmdStartGetFDs(ctl, cmd, &nfds, &fds) < 0)
|
||||||
return false;
|
goto cleanup;
|
||||||
|
|
||||||
if (vshCommandOptBool(cmd, "paused"))
|
if (vshCommandOptBool(cmd, "paused"))
|
||||||
flags |= VIR_DOMAIN_START_PAUSED;
|
flags |= VIR_DOMAIN_START_PAUSED;
|
||||||
@ -6545,20 +6545,23 @@ cmdCreate(vshControl *ctl, const vshCmd *cmd)
|
|||||||
dom = virDomainCreateXMLWithFiles(ctl->conn, buffer, nfds, fds, flags);
|
dom = virDomainCreateXMLWithFiles(ctl->conn, buffer, nfds, fds, flags);
|
||||||
else
|
else
|
||||||
dom = virDomainCreateXML(ctl->conn, buffer, flags);
|
dom = virDomainCreateXML(ctl->conn, buffer, flags);
|
||||||
VIR_FREE(buffer);
|
|
||||||
|
|
||||||
if (dom != NULL) {
|
if (!dom) {
|
||||||
vshPrint(ctl, _("Domain %s created from %s\n"),
|
|
||||||
virDomainGetName(dom), from);
|
|
||||||
#ifndef WIN32
|
|
||||||
if (console)
|
|
||||||
cmdRunConsole(ctl, dom, NULL, 0);
|
|
||||||
#endif
|
|
||||||
virDomainFree(dom);
|
|
||||||
} else {
|
|
||||||
vshError(ctl, _("Failed to create domain from %s"), from);
|
vshError(ctl, _("Failed to create domain from %s"), from);
|
||||||
ret = false;
|
goto cleanup;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
vshPrint(ctl, _("Domain %s created from %s\n"),
|
||||||
|
virDomainGetName(dom), from);
|
||||||
|
#ifndef WIN32
|
||||||
|
if (console)
|
||||||
|
cmdRunConsole(ctl, dom, NULL, 0);
|
||||||
|
#endif
|
||||||
|
virDomainFree(dom);
|
||||||
|
ret = true;
|
||||||
|
|
||||||
|
cleanup:
|
||||||
|
VIR_FREE(buffer);
|
||||||
VIR_FREE(fds);
|
VIR_FREE(fds);
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user