From bb22de2e3e91b22c8e9cb1c1be7da40163738138 Mon Sep 17 00:00:00 2001 From: Pavel Hrdina Date: Mon, 13 Jan 2014 15:42:35 +0100 Subject: [PATCH] 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 --- 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 b29b82a3a7..de4afbb33f 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" -- 2.47.2