From 1f8c33b672773463a6083c4ae876fb07c3d2a4be Mon Sep 17 00:00:00 2001 From: Gao feng Date: Tue, 12 Jun 2012 14:31:15 +0800 Subject: [PATCH] LXC: fix memory leak in lxcContainerGetSubtree 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 --- src/lxc/lxc_container.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/lxc/lxc_container.c b/src/lxc/lxc_container.c index a226e4d94a..3d90c87e86 100644 --- a/src/lxc/lxc_container.c +++ b/src/lxc/lxc_container.c @@ -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) { -- GitLab