1
0
mirror of https://gitlab.com/libvirt/libvirt.git synced 2025-03-07 17:28:15 +00:00

Fix possible memory leak in virsh-domain-monitor.c in cmdDomblklist

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@redhat.com>
This commit is contained in:
Pavel Hrdina 2014-01-13 15:42:35 +01:00
parent 362da8209d
commit bb22de2e3e

View File

@ -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"