[libvirt] [PATCH 0/2] Couple of Coverity fixes

Both from recent changes, it was just as easy for me to post the patches as write the annoying email that someone else needs to generate them ;-). John Ferlan (2): qemu: Fix possible NULL deref in qemuDomainGetResctrlMonData tests: Fix memory leak in mymain src/qemu/qemu_driver.c | 3 ++- tests/virhostdevtest.c | 4 +--- 2 files changed, 3 insertions(+), 4 deletions(-) -- 2.20.1

If virQEMUDriverGetCapabilities returns NULL, then a subsequent deref of @caps would cause an error, so we just return failure. Found by Coverity Signed-off-by: John Ferlan <jferlan@redhat.com> --- src/qemu/qemu_driver.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/qemu/qemu_driver.c b/src/qemu/qemu_driver.c index f1983f33e6..ff83d1c024 100644 --- a/src/qemu/qemu_driver.c +++ b/src/qemu/qemu_driver.c @@ -20728,7 +20728,8 @@ qemuDomainGetResctrlMonData(virQEMUDriverPtr driver, size_t i = 0; size_t j = 0; - caps = virQEMUDriverGetCapabilities(driver, false); + if (!(caps = virQEMUDriverGetCapabilities(driver, false))) + return -1; switch (tag) { case VIR_RESCTRL_MONITOR_TYPE_CACHE: -- 2.20.1

Commit d2899a648 added a new exit path, but didn't free @fakerootdir. Let's just use VIR_AUTOFREE instead to make life easier. Found by Coverity Signed-off-by: John Ferlan <jferlan@redhat.com> --- tests/virhostdevtest.c | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/tests/virhostdevtest.c b/tests/virhostdevtest.c index 7d15a87797..20984f3442 100644 --- a/tests/virhostdevtest.c +++ b/tests/virhostdevtest.c @@ -556,7 +556,7 @@ static int mymain(void) { int ret = 0; - char *fakerootdir; + VIR_AUTOFREE(char *) fakerootdir = NULL; if (VIR_STRDUP_QUIET(fakerootdir, FAKEROOTDIRTEMPLATE) < 0) { fprintf(stderr, "Out of memory\n"); @@ -594,8 +594,6 @@ mymain(void) if (getenv("LIBVIRT_SKIP_CLEANUP") == NULL) virFileDeleteTree(fakerootdir); - VIR_FREE(fakerootdir); - return ret == 0 ? EXIT_SUCCESS : EXIT_FAILURE; } -- 2.20.1

On 8/7/19 4:45 PM, John Ferlan wrote:
Both from recent changes, it was just as easy for me to post the patches as write the annoying email that someone else needs to generate them ;-).
John Ferlan (2): qemu: Fix possible NULL deref in qemuDomainGetResctrlMonData tests: Fix memory leak in mymain
src/qemu/qemu_driver.c | 3 ++- tests/virhostdevtest.c | 4 +--- 2 files changed, 3 insertions(+), 4 deletions(-)
Reviewed-by: Michal Privoznik <mprivozn@redhat.com> Michal
participants (2)
-
John Ferlan
-
Michal Privoznik