In a "for" loop there are created two new strings and they may not
be freed if a "target" string cannot be obtained. We have to free
the two created strings to prevent the memory leak.
This has been found by coverity.
John also pointed out that we should somehow care about the "type"
and "device" and Osier agreed to exit with error message if one of
them is set to NULL.
Signed-off-by: Pavel Hrdina <phrdina(a)redhat.com>
---
version 2:
- initialize "type" and "device" to NULL
- exit with error message if "type" and "device" is NULL
- remove a "if (details)" condition before freeing "type" and
"device"
tools/virsh-domain-monitor.c | 12 ++++++++++--
1 file changed, 10 insertions(+), 2 deletions(-)
diff --git a/tools/virsh-domain-monitor.c b/tools/virsh-domain-monitor.c
index b29b82a..de4afbb 100644
--- a/tools/virsh-domain-monitor.c
+++ b/tools/virsh-domain-monitor.c
@@ -545,8 +545,8 @@ cmdDomblklist(vshControl *ctl, const vshCmd *cmd)
vshPrint(ctl, "------------------------------------------------\n");
for (i = 0; i < ndisks; i++) {
- char *type;
- char *device;
+ char *type = NULL;
+ char *device = NULL;
char *target;
char *source;
@@ -555,11 +555,19 @@ cmdDomblklist(vshControl *ctl, const vshCmd *cmd)
if (details) {
type = virXPathString("string(./@type)", ctxt);
device = virXPathString("string(./@device)", ctxt);
+ if (!type || !device) {
+ vshPrint(ctl, "unable to query block list details");
+ VIR_FREE(type);
+ VIR_FREE(device);
+ goto cleanup;
+ }
}
target = virXPathString("string(./target/@dev)", ctxt);
if (!target) {
vshError(ctl, "unable to query block list");
+ VIR_FREE(type);
+ VIR_FREE(device);
goto cleanup;
}
source = virXPathString("string(./source/@file"
--
1.8.3.1