]> git.ipfire.org Git - thirdparty/libvirt.git/commitdiff
Fix leak in qemuStringToArgvEnv upon OOM
authorDaniel P. Berrange <berrange@redhat.com>
Tue, 24 Sep 2013 15:34:06 +0000 (16:34 +0100)
committerDaniel P. Berrange <berrange@redhat.com>
Wed, 25 Sep 2013 14:49:28 +0000 (15:49 +0100)
The 'qemuStringToArgvEnv' method splits up a string of command
line env/args to an 'arglist' array. It then copies env vars
to a 'progenv' array and args to a 'progargv' array. When
copyin the env vars, it NULL-ifies the element in 'arglist'
that is copied.

Upon OOM the 'virStringListFree' is called on progenv and
arglist. Unfortunately, because the elements in 'arglist'
related to env vars have been set to NULL, the call to
virStringListFree(arglist) doesn't free anything, even
though some non-NULL args vars still exist later in the
array.

To fix this leak, stop NULL-ifying the 'arglist' elements,
and change the cleanup code to only free elements in the
'arglist' array, not 'progenv'.

Signed-off-by: Daniel P. Berrange <berrange@redhat.com>
src/qemu/qemu_command.c

index 992714baf7d785e54d5f6c3697e25111ae20c321..4b4f9c92b0d58c33337de57ed3a3fbf2927c9985 100644 (file)
@@ -9819,10 +9819,8 @@ static int qemuStringToArgvEnv(const char *args,
     if (envend > 0) {
         if (VIR_REALLOC_N(progenv, envend+1) < 0)
             goto error;
-        for (i = 0; i < envend; i++) {
+        for (i = 0; i < envend; i++)
             progenv[i] = arglist[i];
-            arglist[i] = NULL;
-        }
         progenv[i] = NULL;
     }
 
@@ -9841,7 +9839,8 @@ static int qemuStringToArgvEnv(const char *args,
     return 0;
 
 error:
-    virStringFreeList(progenv);
+    VIR_FREE(progenv);
+    VIR_FREE(progargv);
     virStringFreeList(arglist);
     return -1;
 }