From: Wang Rui Date: Thu, 28 Aug 2014 10:20:58 +0000 (+0800) Subject: qemu_capabilities: Resolve Coverity RESOURCE_LEAK X-Git-Url: http://xenbits.xensource.com/gitweb?a=commitdiff_plain;h=6781d5b5a8d006a22f75c938fc7473416eb814cb;p=people%2Fliuw%2Flibxenctrl-split%2Flibvirt.git qemu_capabilities: Resolve Coverity RESOURCE_LEAK 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 --- diff --git a/src/qemu/qemu_capabilities.c b/src/qemu/qemu_capabilities.c index ce899f210..4a540eec9 100644 --- a/src/qemu/qemu_capabilities.c +++ b/src/qemu/qemu_capabilities.c @@ -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);