From 2cfeeac465d35db9ff92befe28742bf88fbbdc55 Mon Sep 17 00:00:00 2001 From: Oleg Nesterov Date: Sun, 29 Mar 2015 19:23:57 +0200 Subject: [PATCH] parse_mountinfo: add the "end" block into the main loop Preparation to simplify the review. parse_mountinfo() assumes that: 1. The "err:" block does all the necessary cleanups on failure. This is wrong, see the next patch. 2. We can never skip the mountpoint. This is true, but we are going to change this. s/goto err/goto end/ in the main loop, add the "end:" label which inserts the new mount_info into the list and then checks ret != 0 to figure out whether we need to abort. Signed-off-by: Oleg Nesterov Reviewed-by: Cyrill Gorcunov Signed-off-by: Pavel Emelyanov --- proc_parse.c | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) diff --git a/proc_parse.c b/proc_parse.c index 2354561fa..909c7cbab 100644 --- a/proc_parse.c +++ b/proc_parse.c @@ -1016,22 +1016,19 @@ struct mount_info *parse_mountinfo(pid_t pid, struct ns_id *nsid) while (fgets(str, sizeof(str), f)) { struct mount_info *new; - int ret; + int ret = -1; char *fst = NULL; new = mnt_entry_alloc(); if (!new) - goto err; + goto end; new->nsid = nsid; - new->next = list; - list = new; - ret = parse_mountinfo_ent(str, new, &fst); if (ret < 0) { pr_err("Bad format in %d mountinfo\n", pid); - goto err; + goto end; } pr_info("\ttype %s source %s mnt_id %d s_dev %#x %s @ %s flags %#x options %s\n", @@ -1044,9 +1041,17 @@ struct mount_info *parse_mountinfo(pid_t pid, struct ns_id *nsid) if (ret) { pr_err("Failed to parse FS specific data on %s\n", new->mountpoint); - goto err; + goto end; } } +end: + if (new) { + new->next = list; + list = new; + } + + if (ret) + goto err; } out: fclose(f);