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

Re: [libvirt] [PATCH] LXC: fix memory leak in lxcContainerGetSubtree



On 2012年06月12日 14:31, Gao feng wrote:
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 |   10 +++++-----
  1 files changed, 5 insertions(+), 5 deletions(-)

diff --git a/src/lxc/lxc_container.c b/src/lxc/lxc_container.c
index 5651255..633218c 100644
--- a/src/lxc/lxc_container.c
+++ b/src/lxc/lxc_container.c
@@ -1118,10 +1118,11 @@ static int lxcContainerGetSubtree(const char *prefix,
              virReportOOMError();
              goto cleanup;
          }
-        if (!(mounts[nmounts++] = strdup(mntent.mnt_dir))) {
+        if (!(mounts[nmounts] = strdup(mntent.mnt_dir))) {

Good catch.

              virReportOOMError();
              goto cleanup;
          }
+	nmounts++;
          VIR_DEBUG("Grabbed %s", mntent.mnt_dir);
      }

@@ -1129,11 +1130,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;
  }
@@ -1151,7 +1151,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) {


Right fix, and ACK.

Osier


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