]> git.ipfire.org Git - thirdparty/libvirt.git/commitdiff
Fix memory leak in securityselinuxlabeltest.c
authorPavel Hrdina <phrdina@redhat.com>
Mon, 13 Jan 2014 15:48:00 +0000 (16:48 +0100)
committerPavel Hrdina <phrdina@redhat.com>
Wed, 15 Jan 2014 10:18:23 +0000 (11:18 +0100)
Strings "file" and "context" may not be freed if "VIR_EXPAND_N" fails
and it leads into memory leak.

This has been found by coverity.

Signed-off-by: Pavel Hrdina <phrdina@redhat.com>
tests/securityselinuxlabeltest.c

index d1fd92f8dade96866ea1d3fc8ba103b997509efe..f98033de551818621133558898f18d401821eb41 100644 (file)
@@ -94,7 +94,7 @@ testSELinuxLoadFileList(const char *testname,
         goto cleanup;
 
     while (!feof(fp)) {
-        char *file, *context, *tmp;
+        char *file = NULL, *context = NULL, *tmp;
         if (!fgets(line, 1024, fp)) {
             if (!feof(fp))
                 goto cleanup;
@@ -123,12 +123,13 @@ testSELinuxLoadFileList(const char *testname,
             tmp = strchr(context, '\n');
             if (tmp)
                 *tmp = '\0';
-        } else {
-            context = NULL;
         }
 
-        if (VIR_EXPAND_N(*files, *nfiles, 1) < 0)
+        if (VIR_EXPAND_N(*files, *nfiles, 1) < 0) {
+            VIR_FREE(file);
+            VIR_FREE(context);
             goto cleanup;
+        }
 
         (*files)[(*nfiles)-1].file = file;
         (*files)[(*nfiles)-1].context = context;