提交 8e9ee30e 编写于 作者: E Eric Blake

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.
上级 c778fe96
...@@ -964,10 +964,12 @@ virCommandRun(virCommandPtr cmd, int *exitstatus) ...@@ -964,10 +964,12 @@ virCommandRun(virCommandPtr cmd, int *exitstatus)
if (!cmd->outfdptr) { if (!cmd->outfdptr) {
cmd->outfdptr = &cmd->outfd; cmd->outfdptr = &cmd->outfd;
cmd->outbuf = &outbuf; cmd->outbuf = &outbuf;
string_io = true;
} }
if (!cmd->errfdptr) { if (!cmd->errfdptr) {
cmd->errfdptr = &cmd->errfd; cmd->errfdptr = &cmd->errfd;
cmd->errbuf = &errbuf; cmd->errbuf = &errbuf;
string_io = true;
} }
if (virCommandRunAsync(cmd, NULL) < 0) { if (virCommandRunAsync(cmd, NULL) < 0) {
...@@ -1009,6 +1011,7 @@ virCommandRun(virCommandPtr cmd, int *exitstatus) ...@@ -1009,6 +1011,7 @@ virCommandRun(virCommandPtr cmd, int *exitstatus)
VIR_DEBUG("ignoring failed close on fd %d", tmpfd); VIR_DEBUG("ignoring failed close on fd %d", tmpfd);
cmd->outfdptr = NULL; cmd->outfdptr = NULL;
cmd->outbuf = NULL; cmd->outbuf = NULL;
VIR_FREE(outbuf);
} }
if (cmd->errbuf == &errbuf) { if (cmd->errbuf == &errbuf) {
int tmpfd = cmd->errfd; int tmpfd = cmd->errfd;
...@@ -1016,6 +1019,7 @@ virCommandRun(virCommandPtr cmd, int *exitstatus) ...@@ -1016,6 +1019,7 @@ virCommandRun(virCommandPtr cmd, int *exitstatus)
VIR_DEBUG("ignoring failed close on fd %d", tmpfd); VIR_DEBUG("ignoring failed close on fd %d", tmpfd);
cmd->errfdptr = NULL; cmd->errfdptr = NULL;
cmd->errbuf = NULL; cmd->errbuf = NULL;
VIR_FREE(errbuf);
} }
return ret; return ret;
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册