git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: "Matthias Andree" <matthias.andree@gmx.de>
To: "Johannes Schindelin" <Johannes.Schindelin@gmx.de>,
	"Thomas Rast" <trast@student.ethz.ch>
Cc: "Martin Ettl" <ettl.martin@gmx.de>, git@vger.kernel.org
Subject: Re: found a resource leak in file builtin-fast-export.c
Date: Thu, 09 Jul 2009 15:36:13 +0200	[thread overview]
Message-ID: <op.uwsyqnwt1e62zd@balu.cs.uni-paderborn.de> (raw)
In-Reply-To: <alpine.DEB.1.00.0907091500420.4339@intel-tinevez-2-302>

Am 09.07.2009, 15:01 Uhr, schrieb Johannes Schindelin  
<Johannes.Schindelin@gmx.de>:

> 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...

I've made such a patch, to appear soon on the list (sorry for not Cc:'ing  
it).

-- 
Matthias Andree

      parent reply	other threads:[~2009-07-09 13:36 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2009-07-09  7:57 found a resource leak in file builtin-fast-export.c Martin Ettl
2009-07-09  8:31 ` Thomas Rast
2009-07-09 11:04   ` Johannes Schindelin
2009-07-09 11:24     ` Thomas Rast
2009-07-09 11:30       ` Andreas Ericsson
2009-07-09 13:01       ` 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
2009-07-09 13:36         ` Matthias Andree [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=op.uwsyqnwt1e62zd@balu.cs.uni-paderborn.de \
    --to=matthias.andree@gmx.de \
    --cc=Johannes.Schindelin@gmx.de \
    --cc=ettl.martin@gmx.de \
    --cc=git@vger.kernel.org \
    --cc=trast@student.ethz.ch \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).