From: Bryan W. Headley <bheadley@interaccess.com>
Subject: Re: fclose()
Date: Mon, 24 Feb 1997 22:08:32 -0600 [thread overview]
Message-ID: <bd0b1273b98fea2a8a68f502345fb238.axp-list@archive.invalid> (raw)
In-Reply-To: <eric@brouhaha.com>
On Feb 24, 7:41pm, Eric Smith wrote:
> Subject: Re: fclose()
> Uncle George <gatgul@voicenet.com> wrote:
> > I just looked at the Linux man pages for fclose(). I shudda looked at
> > them at the beginning of this dialog, but interestingly enough THAT
> > DOCUMENTATION seems to support my view point -under ERRORS:
> > EBADF the argument stream is not an open stream.
>
> Yes, but even if it did that, you *still* wouldn't be safe calling fclose()
> twice on the same stream. Why? Because it would still be possible that
> an intermediate open() call might have returned the same pointer:
>
> f1 = fopen ("foo", "r"); /* returns 28 */
> fclose (f1);
> f2 = fopen ("bar", "r"); /* also returns 28 */
> fclose (f1); /* oops! 28 is still a valid stream! */
> fprintf (f2, "test\n"); /* fails */
Actually, there's a semaphore bit you can set on close that prevents the stream
from looking valid. The library currently uses signature patterns to see if the
stream looks legit, and adding a check for this semaphore bit to that code
would not be hard. Sure, the fprintf() will return an error -- it should. But
I'd rather fail on the signature bit test and immediately return with an error
than to allow fprintf to write to f2->buffer, who got freed in fclose(f1), and
whose state is rather "undefined". SOME wrong code is harder to debug than
others...
I passed the idea to Uli and Richard, let's see what they say...
--
Bryan W. Headley Home: bheadley@interaccess.com
211 East Pineview Drive Office: bwh@abnamro.com
Round Lake Park, IL 60073 Phone: 847 740-1446
--
To unsubscribe: send e-mail to axp-list-request@redhat.com with
'unsubscribe' as the subject. Do not send it to axp-list@redhat.com
next prev parent reply other threads:[~1997-02-25 4:08 UTC|newest]
Thread overview: 24+ messages / expand[flat|nested] mbox.gz Atom feed top
[not found] <eric@brouhaha.com>
1996-11-26 18:50 ` Help with udb please Bryan W. Headley
1996-11-26 23:10 ` jestabro
1997-01-25 20:35 ` New SDRAM Alphas Rich McClellan
1997-02-25 4:08 ` Bryan W. Headley [this message]
1997-05-05 16:15 ` Maddog's talk in Dallas Bryan W. Headley
1997-02-25 10:03 fclose() Uncle George
-- strict thread matches above, loose matches on Subject: below --
1997-02-25 9:52 fclose() Uncle George
1997-02-24 21:17 fclose() Craig Burley
1997-02-24 19:41 fclose() Eric Smith
[not found] <33119E2E.7313@voicenet.com>
1997-02-24 19:34 ` fclose() Richard Henderson
1997-02-24 13:57 fclose() Uncle George
[not found] <330AFE32.5C6E@voicenet.com>
1997-02-19 14:49 ` fclose() Richard Henderson
1997-02-19 17:45 ` fclose() Philip Blundell
1997-02-19 13:20 fclose() Uncle George
[not found] <19970218191335.5758.qmail@brouhaha.com>
1997-02-18 22:32 ` fclose() D. Champion
1997-02-18 19:13 fclose() Eric Smith
1997-02-18 19:11 fclose() Mark Hamstra
1997-02-18 18:06 fclose() Uncle George
[not found] <3309BA67.2168@voicenet.com>
1997-02-18 16:04 ` fclose() Richard Henderson
1997-02-18 14:19 fclose() Uncle George
[not found] <richard@atheist.tamu.edu>
1997-02-17 19:47 ` fclose() Bryan W. Headley
1997-02-17 20:04 ` fclose() Richard Henderson
[not found] <33088AF0.2FF1@voicenet.com>
1997-02-17 19:01 ` fclose() Richard Henderson
1997-02-17 16:44 fclose() Uncle George
read-only archive
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox