[CRIU] [PATCH] proc_parse: double fclose in parse_fdinfo

Vasily Averin vvs at parallels.com
Thu Apr 25 06:04:36 EDT 2013


"crtools check" crashes on ubuntu 12.10
(00.011275) Error (proc_parse.c:1049): No records of type 6 found in fdinfo file
(00.011281) Error (proc_parse.c:1052): parse_fdinfo: error parsing [flags:  02 ] for 6 : Operation not permitted
*** glibc detected *** /home/vvs/devel/criu/crtools/crtools: double free or corruption (top): 0x000000000068a5a0 **

Signed-off-by:  Vasily Averin <vvs at parallels.com>
-------------- next part --------------
--- a/proc_parse.c
+++ b/proc_parse.c
@@ -882,7 +882,7 @@ int parse_fdinfo(int fd, int type,
 				goto parse_err;
 			ret = cb(&entry, arg);
 			if (ret)
-				goto errcode;
+				goto out;
 
 			entry_met = true;
 			continue;
@@ -898,7 +898,7 @@ int parse_fdinfo(int fd, int type,
 				goto parse_err;
 			ret = cb(&entry, arg);
 			if (ret)
-				goto errcode;
+				goto out;
 
 			entry_met = true;
 			continue;
@@ -914,7 +914,7 @@ int parse_fdinfo(int fd, int type,
 				goto parse_err;
 			ret = cb(&entry, arg);
 			if (ret)
-				goto errcode;
+				goto out;
 
 			entry_met = true;
 			continue;
@@ -956,7 +956,7 @@ int parse_fdinfo(int fd, int type,
 
 			if (alloc_fhandle(&f_handle)) {
 				ret = -1;
-				goto errcode;
+				goto out;
 			}
 			parse_fhandle_encoded(str + hoff, &f_handle);
 
@@ -966,7 +966,7 @@ int parse_fdinfo(int fd, int type,
 			free_fhandle(&f_handle);
 
 			if (ret)
-				goto errcode;
+				goto out;
 
 			entry_met = true;
 			continue;
@@ -990,7 +990,7 @@ int parse_fdinfo(int fd, int type,
 			entry.ffy.type = MARK_TYPE__MOUNT;
 			ret = cb(&entry, arg);
 			if (ret)
-				goto errcode;
+				goto out;
 
 			entry_met = true;
 			continue;
@@ -1018,7 +1018,7 @@ int parse_fdinfo(int fd, int type,
 
 			if (alloc_fhandle(&f_handle)) {
 				ret = -1;
-				goto errcode;
+				goto out;
 			}
 
 			parse_fhandle_encoded(str + hoff, entry.ify.f_handle);
@@ -1028,29 +1028,28 @@ int parse_fdinfo(int fd, int type,
 			free_fhandle(&f_handle);
 
 			if (ret)
-				goto errcode;
+				goto out;
 
 			entry_met = true;
 			continue;
 		}
 	}
 
-	fclose(f);
-
+	ret = 0;
 	if (entry_met)
-		return 0;
+		goto out;
 	/*
 	 * An eventpoll/inotify file may have no target fds set thus
 	 * resulting in no tfd: lines in proc. This is normal.
 	 */
 	if (type == FD_TYPES__EVENTPOLL || type == FD_TYPES__INOTIFY)
-		return 0;
+		goto out;
 
 	pr_err("No records of type %d found in fdinfo file\n", type);
 parse_err:
 	ret = -1;
 	pr_perror("%s: error parsing [%s] for %d\n", __func__, str, type);
-errcode:
+out:
 	fclose(f);
 	return ret;
 }


More information about the CRIU mailing list