[libvirt] [PATCH 0/3] Fix some Coverity issues

Patch 1 is technically a build breaker, but since I was fixing my Coverity build I figured I could handle the two more recent memory leaks that also showed up. John Ferlan (3): qemu: Fix qemuBuildCommandLine prototype tools: Fix memory leak Resolve a couple of memory leaks src/qemu/qemu_command.h | 3 +-- src/qemu/qemu_parse_command.c | 3 ++- src/xenconfig/xen_xl.c | 1 + tools/virt-host-validate-common.c | 5 +++-- 4 files changed, 7 insertions(+), 5 deletions(-) -- 2.5.5

Commit id '0da965c5e' removed the 11th parameter, but neglected to remove the ATTRIBUTE_NONNULL for it and adjust the 17th and 18th. Signed-off-by: John Ferlan <jferlan@redhat.com> --- src/qemu/qemu_command.h | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/qemu/qemu_command.h b/src/qemu/qemu_command.h index 4a8ee4b..7fbdbcf 100644 --- a/src/qemu/qemu_command.h +++ b/src/qemu/qemu_command.h @@ -63,8 +63,7 @@ virCommandPtr qemuBuildCommandLine(virConnectPtr conn, int **nicindexes, const char *domainLibDir, const char *domainChannelTargetDir) - ATTRIBUTE_NONNULL(1) ATTRIBUTE_NONNULL(11) - ATTRIBUTE_NONNULL(17) ATTRIBUTE_NONNULL(18); + ATTRIBUTE_NONNULL(1) ATTRIBUTE_NONNULL(16) ATTRIBUTE_NONNULL(17); /* Generate '-device' string for chardev device */ int -- 2.5.5

Coverity found that commit id 'c661b675f' needed to create a cleanup path to handle the closing of 'fp' if the virBitmapNewQuiet failed. Signed-off-by: John Ferlan <jferlan@redhat.com> --- tools/virt-host-validate-common.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/tools/virt-host-validate-common.c b/tools/virt-host-validate-common.c index e182d0c..c476c95 100644 --- a/tools/virt-host-validate-common.c +++ b/tools/virt-host-validate-common.c @@ -194,13 +194,13 @@ int virHostValidateNamespace(const char *hvname, virBitmapPtr virHostValidateGetCPUFlags(void) { FILE *fp; - virBitmapPtr flags; + virBitmapPtr flags = NULL; if (!(fp = fopen("/proc/cpuinfo", "r"))) return NULL; if (!(flags = virBitmapNewQuiet(VIR_HOST_VALIDATE_CPU_FLAG_LAST))) - return NULL; + goto cleanup; do { char line[1024]; @@ -246,6 +246,7 @@ virBitmapPtr virHostValidateGetCPUFlags(void) virStringFreeListCount(tokens, ntokens); } while (1); + cleanup: VIR_FORCE_FCLOSE(fp); return flags; -- 2.5.5

Commit id '4b75237f' seems to have triggered Coverity into finding at least one memory leak in xen_xl.c for error path for cleanup where the listenAddr would be leaked. Reviewing other callers, it seems that qemu_parse_command.c would have the same issue, so just it too. Signed-off-by: John Ferlan <jferlan@redhat.com> --- src/qemu/qemu_parse_command.c | 3 ++- src/xenconfig/xen_xl.c | 1 + 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/src/qemu/qemu_parse_command.c b/src/qemu/qemu_parse_command.c index 6fbb702..79f5b92 100644 --- a/src/qemu/qemu_parse_command.c +++ b/src/qemu/qemu_parse_command.c @@ -500,6 +500,7 @@ qemuParseCommandLineVnc(virDomainDefPtr def, { int ret = -1; virDomainGraphicsDefPtr vnc = NULL; + char *listenAddr = NULL; char *tmp; if (VIR_ALLOC(vnc) < 0) @@ -519,7 +520,6 @@ qemuParseCommandLineVnc(virDomainDefPtr def, char *opts; char *port; const char *sep = ":"; - char *listenAddr = NULL; if (val[0] == '[') sep = "]:"; tmp = strstr(val, sep); @@ -614,6 +614,7 @@ qemuParseCommandLineVnc(virDomainDefPtr def, cleanup: virDomainGraphicsDefFree(vnc); + VIR_FREE(listenAddr); return ret; } diff --git a/src/xenconfig/xen_xl.c b/src/xenconfig/xen_xl.c index b5d4da1..889dd40 100644 --- a/src/xenconfig/xen_xl.c +++ b/src/xenconfig/xen_xl.c @@ -240,6 +240,7 @@ xenParseXLSpice(virConfPtr conf, virDomainDefPtr def) return 0; cleanup: + VIR_FREE(listenAddr); virDomainGraphicsDefFree(graphics); return -1; } -- 2.5.5

On 04/14/2016 10:42 AM, John Ferlan wrote:
Patch 1 is technically a build breaker, but since I was fixing my Coverity build I figured I could handle the two more recent memory leaks that also showed up.
John Ferlan (3): qemu: Fix qemuBuildCommandLine prototype tools: Fix memory leak Resolve a couple of memory leaks
src/qemu/qemu_command.h | 3 +-- src/qemu/qemu_parse_command.c | 3 ++- src/xenconfig/xen_xl.c | 1 + tools/virt-host-validate-common.c | 5 +++-- 4 files changed, 7 insertions(+), 5 deletions(-)
ACK all 3 - Cole
participants (2)
-
Cole Robinson
-
John Ferlan