]> git.ipfire.org Git - thirdparty/libvirt.git/commitdiff
LXC: fix memory leak in lxcContainerGetSubtree
authorGao feng <gaofeng@cn.fujitsu.com>
Tue, 12 Jun 2012 06:31:15 +0000 (14:31 +0800)
committerOsier Yang <jyang@redhat.com>
Mon, 18 Jun 2012 13:28:21 +0000 (21:28 +0800)
when libvirt_lxc trigger oom error in lxcContainerGetSubtree
we should free the alloced memory for mounts.

so when lxcContainerGetSubtree failed,we should do some
memory cleanup in lxcContainerUnmountSubtree.

Signed-off-by: Gao feng <gaofeng@cn.fujitsu.com>
src/lxc/lxc_container.c

index a226e4d94a5efb4b3f78182d08937e6f7d8bef0b..3d90c87e86b6cae7426681a4d2d31bca6630c071 100644 (file)
@@ -1044,10 +1044,11 @@ static int lxcContainerGetSubtree(const char *prefix,
             virReportOOMError();
             goto cleanup;
         }
-        if (!(mounts[nmounts++] = strdup(mntent.mnt_dir))) {
+        if (!(mounts[nmounts] = strdup(mntent.mnt_dir))) {
             virReportOOMError();
             goto cleanup;
         }
+       nmounts++;
         VIR_DEBUG("Grabbed %s", mntent.mnt_dir);
     }
 
@@ -1055,11 +1056,10 @@ static int lxcContainerGetSubtree(const char *prefix,
         qsort(mounts, nmounts, sizeof(mounts[0]),
               lxcContainerChildMountSort);
 
-    *mountsret = mounts;
-    *nmountsret = nmounts;
     ret = 0;
-
 cleanup:
+    *mountsret = mounts;
+    *nmountsret = nmounts;
     endmntent(procmnt);
     return ret;
 }
@@ -1077,7 +1077,7 @@ static int lxcContainerUnmountSubtree(const char *prefix,
     VIR_DEBUG("Unmount subtreee from %s", prefix);
 
     if (lxcContainerGetSubtree(prefix, &mounts, &nmounts) < 0)
-        return -1;
+        goto cleanup;
     for (i = 0 ; i < nmounts ; i++) {
         VIR_DEBUG("Umount %s", mounts[i]);
         if (umount(mounts[i]) < 0) {