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

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

 



On 2012年06月12日 15:01, Osier Yang wrote:
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@xxxxxxxxxxxxxx>
---
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


Pushed.

--
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]