[CRIU] [PATCH 1/2] compel: Don't reclose files already closed

Andrey Vagin avagin at virtuozzo.com
Tue Apr 19 09:10:58 PDT 2016


On Tue, Apr 19, 2016 at 08:07:36AM -0700, Andrey Vagin wrote:
> On Tue, Apr 19, 2016 at 11:07:08AM +0300, Cyrill Gorcunov wrote:
> > In case of error don't re-close files already closed.
> > 
> > https://github.com/xemul/criu/issues/148
> > 
> > Reported-by: Andrew Vagin <avagin at virtuozzo.com>
> > Signed-off-by: Cyrill Gorcunov <gorcunov at openvz.org>

Reviewed-by: Andrey Vagin <avagin at virtuozzo.com>

> > ---
> >  compel/src/main.c | 18 ++++++++++++------
> >  1 file changed, 12 insertions(+), 6 deletions(-)
> > 
> > diff --git a/compel/src/main.c b/compel/src/main.c
> > index ce357aeef9a9..ead50be1facb 100644
> > --- a/compel/src/main.c
> > +++ b/compel/src/main.c
> > @@ -73,12 +73,12 @@ static int piegen(void)
> >  {
> >  	struct stat st;
> >  	void *mem;
> > -	int fd;
> > +	int fd, ret = -1;
> >  
> >  	fd = open(opts.input_filename, O_RDONLY);
> >  	if (fd < 0) {
> >  		pr_perror("Can't open file %s", opts.input_filename);
> > -		goto err;
> > +		return -1;
> >  	}
> >  
> >  	if (fstat(fd, &st)) {
> > @@ -99,15 +99,21 @@ static int piegen(void)
> >  	}
> >  
> >  	if (handle_elf(mem, st.st_size)) {
> > -		fclose(fout);
> > +		close(fd), fd = -1;
> >  		unlink(opts.output_filename);
> >  		goto err;
> >  	}
> >  
> > +	ret = 0;
> > +
> >  err:
> > -	fclose(fout);
> > -	printf("%s generated successfully.\n", opts.output_filename);
> > -	return 0;
> > +	if (fd >= 0)
> > +		close(fd);
> > +	if (fout)
> > +		fclose(fout);
> 
> fout is a global variable, so I think we need to set it to NULL here
> 
> > +	if (!ret)
> > +		printf("%s generated successfully.\n", opts.output_filename);
> > +	return ret;
> >  }
> >  
> >  int main(int argc, char *argv[])
> > -- 
> > 2.5.5
> > 
> _______________________________________________
> CRIU mailing list
> CRIU at openvz.org
> https://lists.openvz.org/mailman/listinfo/criu


More information about the CRIU mailing list