]> git.ipfire.org Git - thirdparty/libvirt.git/commitdiff
command: avoid memory leak
authorEric Blake <eblake@redhat.com>
Wed, 8 Dec 2010 15:03:29 +0000 (08:03 -0700)
committerEric Blake <eblake@redhat.com>
Thu, 9 Dec 2010 16:14:13 +0000 (09:14 -0700)
* src/util/command.c (virCommandRun): Fix yesterday's regression
on logging, and avoid leaking log-only output captures.
Reported by Hu Tao.

src/util/command.c

index e39e9495ef80a295c8e5ec3bf74b01c9e6137621..089e0bd536c093eec934647c78210c028cfb6d2e 100644 (file)
@@ -964,10 +964,12 @@ virCommandRun(virCommandPtr cmd, int *exitstatus)
     if (!cmd->outfdptr) {
         cmd->outfdptr = &cmd->outfd;
         cmd->outbuf = &outbuf;
+        string_io = true;
     }
     if (!cmd->errfdptr) {
         cmd->errfdptr = &cmd->errfd;
         cmd->errbuf = &errbuf;
+        string_io = true;
     }
 
     if (virCommandRunAsync(cmd, NULL) < 0) {
@@ -1009,6 +1011,7 @@ virCommandRun(virCommandPtr cmd, int *exitstatus)
             VIR_DEBUG("ignoring failed close on fd %d", tmpfd);
         cmd->outfdptr = NULL;
         cmd->outbuf = NULL;
+        VIR_FREE(outbuf);
     }
     if (cmd->errbuf == &errbuf) {
         int tmpfd = cmd->errfd;
@@ -1016,6 +1019,7 @@ virCommandRun(virCommandPtr cmd, int *exitstatus)
             VIR_DEBUG("ignoring failed close on fd %d", tmpfd);
         cmd->errfdptr = NULL;
         cmd->errbuf = NULL;
+        VIR_FREE(errbuf);
     }
 
     return ret;