[libvirt] [PATCH] util: don't free dmidecode path string before printing it

The path was freed before printing the error message, resulting in: error : virSysinfoRead:773 : internal error Failed to execute command (null) --- src/util/sysinfo.c | 2 +- 1 files changed, 1 insertions(+), 1 deletions(-) diff --git a/src/util/sysinfo.c b/src/util/sysinfo.c index 92c3539..8ecd1e3 100644 --- a/src/util/sysinfo.c +++ b/src/util/sysinfo.c @@ -765,7 +765,6 @@ virSysinfoRead(void) { } cmd = virCommandNewArgList(path, "-q", "-t", "0,1,4,17", NULL); - VIR_FREE(path); virCommandSetOutputBuffer(cmd, &outbuf); if (virCommandRun(cmd, NULL) < 0) { virReportError(VIR_ERR_INTERNAL_ERROR, @@ -796,6 +795,7 @@ virSysinfoRead(void) { goto no_memory; cleanup: + VIR_FREE(path); VIR_FREE(outbuf); virCommandFree(cmd); -- 1.7.8.6

On 09/18/2012 04:57 AM, Ján Tomko wrote:
The path was freed before printing the error message, resulting in: error : virSysinfoRead:773 : internal error Failed to execute command (null) --- src/util/sysinfo.c | 2 +- 1 files changed, 1 insertions(+), 1 deletions(-)
While this fixes the bug, it is still a less the useful error. virCommandRun() already gives a better error message and we are overriding it. I'd prefer: diff --git i/src/util/sysinfo.c w/src/util/sysinfo.c index 92c3539..7f0a45b 100644 --- i/src/util/sysinfo.c +++ w/src/util/sysinfo.c @@ -767,12 +767,8 @@ virSysinfoRead(void) { cmd = virCommandNewArgList(path, "-q", "-t", "0,1,4,17", NULL); VIR_FREE(path); virCommandSetOutputBuffer(cmd, &outbuf); - if (virCommandRun(cmd, NULL) < 0) { - virReportError(VIR_ERR_INTERNAL_ERROR, - _("Failed to execute command %s"), - path); + if (virCommandRun(cmd, NULL) < 0) goto cleanup; - } if (VIR_ALLOC(ret) < 0) goto no_memory; -- Eric Blake eblake@redhat.com +1-919-301-3266 Libvirt virtualization library http://libvirt.org

On Tue, Sep 18, 2012 at 17:33:57 -0600, Eric Blake wrote:
On 09/18/2012 04:57 AM, Ján Tomko wrote:
The path was freed before printing the error message, resulting in: error : virSysinfoRead:773 : internal error Failed to execute command (null) --- src/util/sysinfo.c | 2 +- 1 files changed, 1 insertions(+), 1 deletions(-)
While this fixes the bug, it is still a less the useful error. virCommandRun() already gives a better error message and we are overriding it. I'd prefer:
diff --git i/src/util/sysinfo.c w/src/util/sysinfo.c index 92c3539..7f0a45b 100644 --- i/src/util/sysinfo.c +++ w/src/util/sysinfo.c @@ -767,12 +767,8 @@ virSysinfoRead(void) { cmd = virCommandNewArgList(path, "-q", "-t", "0,1,4,17", NULL); VIR_FREE(path); virCommandSetOutputBuffer(cmd, &outbuf); - if (virCommandRun(cmd, NULL) < 0) { - virReportError(VIR_ERR_INTERNAL_ERROR, - _("Failed to execute command %s"), - path); + if (virCommandRun(cmd, NULL) < 0) goto cleanup; - }
if (VIR_ALLOC(ret) < 0) goto no_memory;
Indeed, ACK to this version. Jirka

On 09/19/2012 05:59 AM, Jiri Denemark wrote:
On Tue, Sep 18, 2012 at 17:33:57 -0600, Eric Blake wrote:
On 09/18/2012 04:57 AM, Ján Tomko wrote:
The path was freed before printing the error message, resulting in: error : virSysinfoRead:773 : internal error Failed to execute command (null) --- src/util/sysinfo.c | 2 +- 1 files changed, 1 insertions(+), 1 deletions(-)
While this fixes the bug, it is still a less the useful error. virCommandRun() already gives a better error message and we are overriding it. I'd prefer:
Indeed, ACK to this version.
Thanks; pushed. -- Eric Blake eblake@redhat.com +1-919-301-3266 Libvirt virtualization library http://libvirt.org
participants (3)
-
Eric Blake
-
Jiri Denemark
-
Ján Tomko