mirror of
https://github.com/checkpoint-restore/criu
synced 2025-08-31 06:15:24 +00:00
parse_mountinfo: fix and simplify the usage of r_fstype
1. parse_mountinfo() forgets to free(fst) if parse_mountinfo_ent() succeeds. 2. The usage of fst/r_fstype is ovecomplicated for no reason. Just change the parse_mountinfo() paths to populate/use/free this fsname unconditionally, and move the ownership to the caller. There is no reason to check FSTYPE__UNSUPPORTED and/or fallback to ->name. Better yet, we could even turn fsname into the local "char []" and avoid %ms and free(), but then we would need to pass the length of this buffer to parse_mountinfo_ent(). Signed-off-by: Oleg Nesterov <oleg@redhat.com> Reviewed-by: Cyrill Gorcunov <gorcunov@openvz.org> Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
This commit is contained in:
committed by
Pavel Emelyanov
parent
2cfeeac465
commit
b66728ef14
22
proc_parse.c
22
proc_parse.c
@@ -943,12 +943,11 @@ static int parse_mnt_opt(char *str, struct mount_info *mi, int *off)
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int parse_mountinfo_ent(char *str, struct mount_info *new, char **r_fstype)
|
||||
static int parse_mountinfo_ent(char *str, struct mount_info *new, char **fsname)
|
||||
{
|
||||
unsigned int kmaj, kmin;
|
||||
int ret, n;
|
||||
char *opt;
|
||||
char *fstype;
|
||||
|
||||
new->mountpoint = xmalloc(PATH_MAX);
|
||||
if (new->mountpoint == NULL)
|
||||
@@ -978,15 +977,13 @@ static int parse_mountinfo_ent(char *str, struct mount_info *new, char **r_fstyp
|
||||
return -1;
|
||||
|
||||
str += n;
|
||||
ret = sscanf(str, "%ms %ms %ms", &fstype, &new->source, &opt);
|
||||
ret = sscanf(str, "%ms %ms %ms", fsname, &new->source, &opt);
|
||||
if (ret != 3)
|
||||
return -1;
|
||||
|
||||
ret = -1;
|
||||
new->fstype = find_fstype_by_name(fstype);
|
||||
if (new->fstype->code == FSTYPE__UNSUPPORTED)
|
||||
*r_fstype = fstype; /* keep for logging */
|
||||
new->fstype = find_fstype_by_name(*fsname);
|
||||
|
||||
ret = -1;
|
||||
new->options = xmalloc(strlen(opt) + 1);
|
||||
if (!new->options)
|
||||
goto err;
|
||||
@@ -997,8 +994,6 @@ static int parse_mountinfo_ent(char *str, struct mount_info *new, char **r_fstyp
|
||||
ret = 0;
|
||||
err:
|
||||
free(opt);
|
||||
if (!*r_fstype)
|
||||
free(fstype);
|
||||
return ret;
|
||||
}
|
||||
|
||||
@@ -1017,7 +1012,7 @@ struct mount_info *parse_mountinfo(pid_t pid, struct ns_id *nsid)
|
||||
while (fgets(str, sizeof(str), f)) {
|
||||
struct mount_info *new;
|
||||
int ret = -1;
|
||||
char *fst = NULL;
|
||||
char *fsname = NULL;
|
||||
|
||||
new = mnt_entry_alloc();
|
||||
if (!new)
|
||||
@@ -1025,14 +1020,14 @@ struct mount_info *parse_mountinfo(pid_t pid, struct ns_id *nsid)
|
||||
|
||||
new->nsid = nsid;
|
||||
|
||||
ret = parse_mountinfo_ent(str, new, &fst);
|
||||
ret = parse_mountinfo_ent(str, new, &fsname);
|
||||
if (ret < 0) {
|
||||
pr_err("Bad format in %d mountinfo\n", pid);
|
||||
goto end;
|
||||
}
|
||||
|
||||
pr_info("\ttype %s source %s mnt_id %d s_dev %#x %s @ %s flags %#x options %s\n",
|
||||
fst ? : new->fstype->name, new->source,
|
||||
fsname, new->source,
|
||||
new->mnt_id, new->s_dev, new->root, new->mountpoint,
|
||||
new->flags, new->options);
|
||||
|
||||
@@ -1045,6 +1040,9 @@ struct mount_info *parse_mountinfo(pid_t pid, struct ns_id *nsid)
|
||||
}
|
||||
}
|
||||
end:
|
||||
if (fsname)
|
||||
free(fsname);
|
||||
|
||||
if (new) {
|
||||
new->next = list;
|
||||
list = new;
|
||||
|
Reference in New Issue
Block a user