提交 1f8c33b6 编写于 作者: G Gao feng 提交者: Osier Yang

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: NGao feng <gaofeng@cn.fujitsu.com>
上级 73e2d646
......@@ -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) {
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册