]> xenbits.xensource.com Git - libvirt.git/commitdiff
qemu_capabilities: Resolve Coverity RESOURCE_LEAK
authorWang Rui <moon.wangrui@huawei.com>
Thu, 28 Aug 2014 10:20:58 +0000 (18:20 +0800)
committerJán Tomko <jtomko@redhat.com>
Thu, 28 Aug 2014 10:52:42 +0000 (12:52 +0200)
In function virQEMUCapsParseMachineTypesStr, VIR_STRNDUP allocates
memory for 'name' in {do,while} loop. If 'name' isn't freed before
'continue', its memory will be allocated again in the next loop.
In this case the memory allocated for 'name' in privious loop is
useless and not freed. Free it before continue this loop to fix that.

Signed-off-by: Wang Rui <moon.wangrui@huawei.com>
src/qemu/qemu_capabilities.c

index ce899f210d4affdc4aa24feb31135c2092171142..4a540eec9e73d6f77aacb6da1b0962bb800db3e3 100644 (file)
@@ -433,8 +433,10 @@ virQEMUCapsParseMachineTypesStr(const char *output,
 
         if ((t = strstr(p, "(alias of ")) && (!next || t < next)) {
             p = t + strlen("(alias of ");
-            if (!(t = strchr(p, ')')) || (next && t >= next))
+            if (!(t = strchr(p, ')')) || (next && t >= next)) {
+                VIR_FREE(name);
                 continue;
+            }
 
             if (VIR_STRNDUP(canonical, p, t - p) < 0) {
                 VIR_FREE(name);