[libvirt] [PATCH 0/3] Coverity patches to resolve RESOURCE_LEAK

I did coverity scan for libvirt-1.2.8 as John Ferlan did. He has sent many patches about RESOURCE_LEAK. I picked the other errors left to fix. There are also many errors to analyze and fix in the future. Wang Rui (3): util: Resolve Coverity RESOURCE_LEAK tests: Resolve Coverity RESOURCE_LEAK qemu_capabilities: Resolve Coverity RESOURCE_LEAK src/qemu/qemu_capabilities.c | 4 +++- src/util/virpci.c | 1 + tests/shunloadtest.c | 1 + 3 files changed, 5 insertions(+), 1 deletion(-) -- 1.7.12.4

Coverity determined that 'conflict' would be leaked. Signed-off-by: Wang Rui <moon.wangrui@huawei.com> --- src/util/virpci.c | 1 + 1 file changed, 1 insertion(+) diff --git a/src/util/virpci.c b/src/util/virpci.c index 0098d6c..f1d4499 100644 --- a/src/util/virpci.c +++ b/src/util/virpci.c @@ -801,6 +801,7 @@ virPCIDeviceTrySecondaryBusReset(virPCIDevicePtr dev, virReportError(VIR_ERR_INTERNAL_ERROR, _("Active %s devices on bus with %s, not doing bus reset"), conflict->name, dev->name); + virPCIDeviceFree(conflict); return -1; } -- 1.7.12.4

The 'lib' handle will be leaked if 'dlsym' condition fails. So close the handle before return. Signed-off-by: Wang Rui <moon.wangrui@huawei.com> --- tests/shunloadtest.c | 1 + 1 file changed, 1 insertion(+) diff --git a/tests/shunloadtest.c b/tests/shunloadtest.c index 499b1be..80f5351 100644 --- a/tests/shunloadtest.c +++ b/tests/shunloadtest.c @@ -114,6 +114,7 @@ int main(int argc ATTRIBUTE_UNUSED, char **argv) } if (!(startup = dlsym(lib, "shunloadStart"))) { fprintf(stderr, "Cannot find shunloadStart %s\n", dlerror()); + dlclose(lib); return 1; } -- 1.7.12.4

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 | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/qemu/qemu_capabilities.c b/src/qemu/qemu_capabilities.c index ce899f2..4a540ee 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); -- 1.7.12.4

On 08/28/2014 12:20 PM, Wang Rui wrote:
I did coverity scan for libvirt-1.2.8 as John Ferlan did.
Technically, libvirt-1.2.8 is not yet released, just -rc1 :)
He has sent many patches about RESOURCE_LEAK. I picked the other errors left to fix. There are also many errors to analyze and fix in the future.
Wang Rui (3): util: Resolve Coverity RESOURCE_LEAK tests: Resolve Coverity RESOURCE_LEAK qemu_capabilities: Resolve Coverity RESOURCE_LEAK
src/qemu/qemu_capabilities.c | 4 +++- src/util/virpci.c | 1 + tests/shunloadtest.c | 1 + 3 files changed, 5 insertions(+), 1 deletion(-)
ACK series; now pushed. Jan
participants (2)
-
Ján Tomko
-
Wang Rui