Skip site navigation (1)Skip section navigation (2)
Date:      Mon, 7 Sep 1998 08:00:02 -0700 (PDT)
From:      Martin Cracauer <cracauer@cons.org>
To:        freebsd-bugs@FreeBSD.ORG
Subject:   Re: bin/7742: fclose(3) dumps core on NULL
Message-ID:  <199809071500.IAA20260@freefall.freebsd.org>

next in thread | raw e-mail | index | archive | help
The following reply was made to PR bin/7742; it has been noted by GNATS.

From: Martin Cracauer <cracauer@cons.org>
To: wb@yorikke.arb-phys.uni-dortmund.de, FreeBSD-gnats-submit@FreeBSD.ORG
Cc:  Subject: Re: bin/7742: fclose(3) dumps core on NULL
Date: Mon, 7 Sep 1998 16:47:38 +0200

 --6TrnltStXW4iwmi0
 Content-Type: text/plain; charset=us-ascii
 
 In <199808251359.PAA17757@yorikke.arb-phys.uni-dortmund.de>, Wilhelm B. Kloke wrote: 
 > 	I found for the 2nd time that installing a program failed
 > 	for fclose coredumping when ivoked with NULL. (teTeX-0.9)
 
 > 	The man page doe not say anything on this. But it seems
 > 	programming practice, closing a file after open, even if
 > 	the open failed.
 > 	So the library fclose should return gracefully when
 > 	invoked with NULL.
 
 Urgs. I understand people want to close "just in case some resources
 are left over" from the failed open.
 
 Sadly, this is complete nonsense, since the FILE pointer doesn't point
 to anything that resembles a pointer to anything to clean up if it is
 NULL and fopen doesn't return anything else than NULL on errors.
 
 I checked that SunOS, Solaris and Linux actually support this, and I
 think we can do so as well, since:
 - The cost is near zero, since the pointer we check is followed
   anyway. 
 - There is a way to report the error, a careful programmer (checking
   the return value of fclose) will be notified on the error
   nothingtheless. 
 - The probability that the NULL pointer is carried around further by the
   caller is low.
 
 I could commit the fix as follows, but could someone with more
 authority approve it, please? I don't want to be eaten alive :-)
 
 Martin
 -- 
 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
 Martin Cracauer <cracauer@cons.org> http://www.cons.org/cracauer/
 BSD User Group Hamburg/Germany      http://www.bsdhh.org/
 
 --6TrnltStXW4iwmi0
 Content-Type: text/plain; charset=us-ascii
 Content-Disposition: attachment; filename=diff
 
 Index: fclose.c
 ===================================================================
 RCS file: /home/ncvs/src/lib/libc/stdio/fclose.c,v
 retrieving revision 1.6
 diff -c -r1.6 fclose.c
 *** fclose.c	1998/04/11 07:40:42	1.6
 --- fclose.c	1998/09/07 14:14:21
 ***************
 *** 54,60 ****
   {
   	register int r;
   
 ! 	if (fp->_flags == 0) {	/* not open! */
   		errno = EBADF;
   		return (EOF);
   	}
 --- 54,60 ----
   {
   	register int r;
   
 ! 	if (fp == NULL || fp->_flags == 0) {	/* not open! */
   		errno = EBADF;
   		return (EOF);
   	}
 
 --6TrnltStXW4iwmi0--

To Unsubscribe: send mail to majordomo@FreeBSD.org
with "unsubscribe freebsd-bugs" in the body of the message



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?199809071500.IAA20260>