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 <gaofeng@cn.fujitsu.com>
This commit is contained in:
Gao feng 2012-06-12 14:31:15 +08:00 committed by Osier Yang
parent 73e2d646fb
commit 1f8c33b672

View 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);
ret = 0;
cleanup:
*mountsret = mounts;
*nmountsret = nmounts;
ret = 0;
cleanup:
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) {