mirror of
https://github.com/checkpoint-restore/criu
synced 2025-09-01 14:55:39 +00:00
mount: free all parts of mnt entries
mnt_entry contains a few strings and they should be release too CID 996198 (#4 of 4): Resource leak (RESOURCE_LEAK) 20. leaked_storage: Variable "pm" going out of scope leaks the storage it points to. CID 996190 (#1 of 1): Resource leak (RESOURCE_LEAK) 13. leaked_storage: Variable "new" going out of scope leaks the storage it points to. Signed-off-by: Andrey Vagin <avagin@openvz.org> Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
This commit is contained in:
committed by
Pavel Emelyanov
parent
edc865361e
commit
6a49f82fb6
@@ -117,11 +117,8 @@ struct mount_info {
|
|||||||
struct list_head siblings;
|
struct list_head siblings;
|
||||||
};
|
};
|
||||||
|
|
||||||
static inline void mnt_entry_init(struct mount_info *pm)
|
extern struct mount_info *mnt_entry_alloc();
|
||||||
{
|
extern void mnt_entry_free(struct mount_info *mi);
|
||||||
pm->parent = NULL;
|
|
||||||
INIT_LIST_HEAD(&pm->children);
|
|
||||||
}
|
|
||||||
|
|
||||||
struct vm_area_list;
|
struct vm_area_list;
|
||||||
|
|
||||||
|
40
mount.c
40
mount.c
@@ -633,6 +633,37 @@ static int cr_pivot_root()
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
struct mount_info *mnt_entry_alloc()
|
||||||
|
{
|
||||||
|
struct mount_info *new;
|
||||||
|
|
||||||
|
new = xmalloc(sizeof(struct mount_info));
|
||||||
|
if (new == NULL)
|
||||||
|
return NULL;
|
||||||
|
|
||||||
|
new->root = NULL;
|
||||||
|
new->mountpoint = NULL;
|
||||||
|
new->source = NULL;
|
||||||
|
new->options = NULL;
|
||||||
|
|
||||||
|
new->parent = NULL;
|
||||||
|
INIT_LIST_HEAD(&new->children);
|
||||||
|
|
||||||
|
return new;
|
||||||
|
}
|
||||||
|
|
||||||
|
void mnt_entry_free(struct mount_info *mi)
|
||||||
|
{
|
||||||
|
if (mi == NULL)
|
||||||
|
return;
|
||||||
|
|
||||||
|
xfree(mi->root);
|
||||||
|
xfree(mi->mountpoint);
|
||||||
|
xfree(mi->source);
|
||||||
|
xfree(mi->options);
|
||||||
|
xfree(mi);
|
||||||
|
}
|
||||||
|
|
||||||
static int populate_mnt_ns(int ns_pid)
|
static int populate_mnt_ns(int ns_pid)
|
||||||
{
|
{
|
||||||
MntEntry *me = NULL;
|
MntEntry *me = NULL;
|
||||||
@@ -654,11 +685,12 @@ static int populate_mnt_ns(int ns_pid)
|
|||||||
if (ret <= 0)
|
if (ret <= 0)
|
||||||
break;
|
break;
|
||||||
|
|
||||||
pm = xmalloc(sizeof(*pm));
|
pm = mnt_entry_alloc();
|
||||||
if (!pm)
|
if (!pm)
|
||||||
goto err;
|
goto err;
|
||||||
|
|
||||||
mnt_entry_init(pm);
|
pm->next = pms;
|
||||||
|
pms = pm;
|
||||||
|
|
||||||
pm->mnt_id = me->mnt_id;
|
pm->mnt_id = me->mnt_id;
|
||||||
pm->parent_mnt_id = me->parent_mnt_id;
|
pm->parent_mnt_id = me->parent_mnt_id;
|
||||||
@@ -689,8 +721,6 @@ static int populate_mnt_ns(int ns_pid)
|
|||||||
goto err;
|
goto err;
|
||||||
|
|
||||||
pr_debug("\tRead %d mp @ %s\n", pm->mnt_id, pm->mountpoint);
|
pr_debug("\tRead %d mp @ %s\n", pm->mnt_id, pm->mountpoint);
|
||||||
pm->next = pms;
|
|
||||||
pms = pm;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (me)
|
if (me)
|
||||||
@@ -708,7 +738,7 @@ err:
|
|||||||
while (pms) {
|
while (pms) {
|
||||||
struct mount_info *pm = pms;
|
struct mount_info *pm = pms;
|
||||||
pms = pm->next;
|
pms = pm->next;
|
||||||
xfree(pm);
|
mnt_entry_free(pm);
|
||||||
}
|
}
|
||||||
close_safe(&img);
|
close_safe(&img);
|
||||||
return -1;
|
return -1;
|
||||||
|
10
proc_parse.c
10
proc_parse.c
@@ -799,11 +799,12 @@ struct mount_info *parse_mountinfo(pid_t pid)
|
|||||||
struct mount_info *new;
|
struct mount_info *new;
|
||||||
int ret;
|
int ret;
|
||||||
|
|
||||||
new = xmalloc(sizeof(*new));
|
new = mnt_entry_alloc();
|
||||||
if (!new)
|
if (!new)
|
||||||
goto err;
|
goto err;
|
||||||
|
|
||||||
mnt_entry_init(new);
|
new->next = list;
|
||||||
|
list = new;
|
||||||
|
|
||||||
ret = parse_mountinfo_ent(str, new);
|
ret = parse_mountinfo_ent(str, new);
|
||||||
if (ret < 0) {
|
if (ret < 0) {
|
||||||
@@ -815,9 +816,6 @@ struct mount_info *parse_mountinfo(pid_t pid)
|
|||||||
new->fstype->name, new->source,
|
new->fstype->name, new->source,
|
||||||
new->s_dev, new->root, new->mountpoint,
|
new->s_dev, new->root, new->mountpoint,
|
||||||
new->flags, new->options);
|
new->flags, new->options);
|
||||||
|
|
||||||
new->next = list;
|
|
||||||
list = new;
|
|
||||||
}
|
}
|
||||||
out:
|
out:
|
||||||
fclose(f);
|
fclose(f);
|
||||||
@@ -826,7 +824,7 @@ out:
|
|||||||
err:
|
err:
|
||||||
while (list) {
|
while (list) {
|
||||||
struct mount_info *next = list->next;
|
struct mount_info *next = list->next;
|
||||||
xfree(list);
|
mnt_entry_free(list);
|
||||||
list = next;
|
list = next;
|
||||||
}
|
}
|
||||||
goto out;
|
goto out;
|
||||||
|
Reference in New Issue
Block a user