[libvirt] [PATCH] virsh: Don't leak buffer if GetFDs fails in cmdCreate

2014-02-24 Thread Ján Tomko
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
---
 tools/virsh-domain.c | 29 -
 1 file changed, 16 insertions(+), 13 deletions(-)

diff --git a/tools/virsh-domain.c b/tools/virsh-domain.c
index 00ace11..59e843f 100644
--- a/tools/virsh-domain.c
+++ b/tools/virsh-domain.c
@@ -6518,7 +6518,7 @@ cmdCreate(vshControl *ctl, const vshCmd *cmd)
 {
 virDomainPtr dom;
 const char *from = NULL;
-bool ret = true;
+bool ret = false;
 char *buffer;
 #ifndef WIN32
 bool console = vshCommandOptBool(cmd, console);
@@ -6534,7 +6534,7 @@ cmdCreate(vshControl *ctl, const vshCmd *cmd)
 return false;
 
 if (cmdStartGetFDs(ctl, cmd, nfds, fds)  0)
-return false;
+goto cleanup;
 
 if (vshCommandOptBool(cmd, paused))
 flags |= VIR_DOMAIN_START_PAUSED;
@@ -6545,20 +6545,23 @@ cmdCreate(vshControl *ctl, const vshCmd *cmd)
 dom = virDomainCreateXMLWithFiles(ctl-conn, buffer, nfds, fds, flags);
 else
 dom = virDomainCreateXML(ctl-conn, buffer, flags);
-VIR_FREE(buffer);
 
-if (dom != NULL) {
-vshPrint(ctl, _(Domain %s created from %s\n),
- virDomainGetName(dom), from);
-#ifndef WIN32
-if (console)
-cmdRunConsole(ctl, dom, NULL, 0);
-#endif
-virDomainFree(dom);
-} else {
+if (!dom) {
 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);
 return ret;
 }
-- 
1.8.3.2

--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list


Re: [libvirt] [PATCH] virsh: Don't leak buffer if GetFDs fails in cmdCreate

2014-02-24 Thread Eric Blake
On 02/24/2014 06:29 AM, Ján Tomko wrote:
 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
 ---
  tools/virsh-domain.c | 29 -
  1 file changed, 16 insertions(+), 13 deletions(-)
 

ACK

-- 
Eric Blake   eblake redhat com+1-919-301-3266
Libvirt virtualization library http://libvirt.org



signature.asc
Description: OpenPGP digital signature
--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list

Re: [libvirt] [PATCH] virsh: Don't leak buffer if GetFDs fails in cmdCreate

2014-02-24 Thread Ján Tomko
On 02/24/2014 05:49 PM, Eric Blake wrote:
 On 02/24/2014 06:29 AM, Ján Tomko wrote:
 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
 ---
  tools/virsh-domain.c | 29 -
  1 file changed, 16 insertions(+), 13 deletions(-)

 
 ACK
 

Thank you, now pushed.

Jan




signature.asc
Description: OpenPGP digital signature
--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list