Commit bd69c617 authored by Pavel Emelyanov's avatar Pavel Emelyanov

mount: Free old mounts for pivot-root case

If we specify a new root for restore old mounts get destroyed
with pivot_root + umount calls, tree umount is omitted. In this
case mi-s are leaked.
Signed-off-by: 's avatarPavel Emelyanov <xemul@parallels.com>
parent f35d7cd7
...@@ -1117,7 +1117,6 @@ static int do_umount_one(struct mount_info *mi) ...@@ -1117,7 +1117,6 @@ static int do_umount_one(struct mount_info *mi)
static int clean_mnt_ns(void) static int clean_mnt_ns(void)
{ {
int ret;
struct mount_info *pm; struct mount_info *pm;
pr_info("Cleaning mount namespace\n"); pr_info("Cleaning mount namespace\n");
...@@ -1131,20 +1130,11 @@ static int clean_mnt_ns(void) ...@@ -1131,20 +1130,11 @@ static int clean_mnt_ns(void)
return -1; return -1;
} }
mntinfo_tree = NULL;
pm = mnt_build_tree(mntinfo); pm = mnt_build_tree(mntinfo);
if (!pm) if (!pm)
return -1; return -1;
ret = mnt_tree_for_each_reverse(pm, do_umount_one); return mnt_tree_for_each_reverse(pm, do_umount_one);
while (mntinfo) {
pm = mntinfo->next;
xfree(mntinfo);
mntinfo = pm;
}
return ret;
} }
static int cr_pivot_root() static int cr_pivot_root()
...@@ -1213,6 +1203,19 @@ void mnt_entry_free(struct mount_info *mi) ...@@ -1213,6 +1203,19 @@ void mnt_entry_free(struct mount_info *mi)
xfree(mi); xfree(mi);
} }
static void free_mounts(void)
{
mntinfo_tree = NULL;
while (mntinfo) {
struct mount_info *pm;
pm = mntinfo->next;
mnt_entry_free(mntinfo);
mntinfo = pm;
}
}
static int populate_mnt_ns(int ns_pid) static int populate_mnt_ns(int ns_pid)
{ {
MntEntry *me = NULL; MntEntry *me = NULL;
...@@ -1319,6 +1322,8 @@ int prepare_mnt_ns(int ns_pid) ...@@ -1319,6 +1322,8 @@ int prepare_mnt_ns(int ns_pid)
else else
ret = clean_mnt_ns(); ret = clean_mnt_ns();
free_mounts();
if (!ret) if (!ret)
ret = populate_mnt_ns(ns_pid); ret = populate_mnt_ns(ns_pid);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment