[PATCH 2/3] tools: Fix memory leak

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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@xxxxxxxxxx>
---
 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

--
libvir-list mailing list
libvir-list@xxxxxxxxxx
https://www.redhat.com/mailman/listinfo/libvir-list



[Index of Archives]     [Virt Tools]     [Libvirt Users]     [Lib OS Info]     [Fedora Users]     [Fedora Desktop]     [Fedora SELinux]     [Big List of Linux Books]     [Yosemite News]     [KDE Users]     [Fedora Tools]