git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* Re: found a resource leak in file builtin-fast-export.c
@ 2009-07-09 13:01 Johannes Schindelin
  2009-07-09 13:28 ` [PATCH] Fix export_marks() error handling Matthias Andree
  0 siblings, 1 reply; 5+ messages in thread
From: Johannes Schindelin @ 2009-07-09 13:01 UTC (permalink / raw)
  To: Thomas Rast; +Cc: Martin Ettl, git

Hi,

On Thu, 9 Jul 2009, Thomas Rast wrote:

> Johannes Schindelin wrote:
> > On Thu, 9 Jul 2009, Thomas Rast wrote:
> > 
> > > Martin Ettl wrote:
> > > > -	if (ferror(f) || fclose(f))
> > > > +	if (ferror(f))
> > > >  		error("Unable to write marks file %s.", file);
> > > > +  	fclose(f);
> > > 
> > > You no longer check the error returned by fclose().  This is
> > > important, because the FILE* API may buffer writes, and a write error
> > > may only become apparent when fclose() flushes the file.
> > 
> > Indeed.  A better fix would be to replace the || by a |, but this must be 
> > accompanied by a comment so it does not get removed due to overzealous 
> > compiler warnings.
> 
> Are you allowed to do that?  IIRC using | no longer guarantees that
> ferror() is called before fclose(), and my local 'man 3p fclose' says
> that
> 
>        After the call to fclose(), any use of stream results in
>        undefined behavior.

Good point.  So we really need something like

	err = ferror(f);
	err |= fclose(f); /* call fclose() even if there was an error */
	if (err)
		error...

Ciao,
Dscho

^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2009-07-24 16:36 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
     [not found] <7v7hxyyfcg.fsf@alter.siamese.dyndns.org>
2009-07-24  8:17 ` [PATCH] Fix export_marks() error handling Matthias Andree
2009-07-24 16:35   ` Junio C Hamano
2009-07-09 13:01 found a resource leak in file builtin-fast-export.c Johannes Schindelin
2009-07-09 13:28 ` [PATCH] Fix export_marks() error handling Matthias Andree
2009-07-11  9:45   ` Stephen R. van den Berg
2009-07-13  8:01     ` Matthias Andree

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).