From: Eric Blake Date: Wed, 8 Dec 2010 15:03:29 +0000 (-0700) Subject: command: avoid memory leak X-Git-Tag: v0.8.7~128 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=8e9ee30e8abca0bdf01345158e1d13cd6d5a400a;p=thirdparty%2Flibvirt.git command: avoid memory leak * src/util/command.c (virCommandRun): Fix yesterday's regression on logging, and avoid leaking log-only output captures. Reported by Hu Tao. --- diff --git a/src/util/command.c b/src/util/command.c index e39e9495ef..089e0bd536 100644 --- a/src/util/command.c +++ b/src/util/command.c @@ -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;