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

Vasily Averin vvs at parallels.com
Thu Apr 25 06:22:09 EDT 2013


On 04/25/2013 02:16 PM, Cyrill Gorcunov wrote:
> On Thu, Apr 25, 2013 at 02:04:36PM +0400, Vasily Averin wrote:
>> "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>
> 
> This looks like a big hammer to me ;) I guess better to introduce
> fclose_safe helper (as we have for close_safe()) or some shorter
> patch as below.

it's up to you, but IMHO it's better to have resource cleanup in one place.

> ---
> From: Cyrill Gorcunov <gorcunov at openvz.org>
> Date: Thu, 25 Apr 2013 14:14:14 +0400
> Subject: [PATCH] proc_parse: Don't close file stream twice
> 
> | "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 **
> 
> Reported-by: Vasily Averin <vvs at parallels.com>
> Signed-off-by: Cyrill Gorcunov <gorcunov at openvz.org>
> ---
>  proc_parse.c | 11 +++++++----
>  1 file changed, 7 insertions(+), 4 deletions(-)
> 
> diff --git a/proc_parse.c b/proc_parse.c
> index 6920bd4..f372c69 100644
> --- a/proc_parse.c
> +++ b/proc_parse.c
> @@ -1035,16 +1035,19 @@ int parse_fdinfo(int fd, int type,
>  		}
>  	}
>  
> -	fclose(f);
> -
> -	if (entry_met)
> +	if (entry_met) {
> +		fclose(f);
>  		return 0;
> +	}
> +
>  	/*
>  	 * 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)
> +	if (type == FD_TYPES__EVENTPOLL || type == FD_TYPES__INOTIFY) {
> +		fclose(f);
>  		return 0;
> +	}
>  
>  	pr_err("No records of type %d found in fdinfo file\n", type);
>  parse_err:
> 



More information about the CRIU mailing list