From owner-freebsd-bugs Mon Sep 7 08:00:30 1998 Return-Path: Received: (from majordom@localhost) by hub.freebsd.org (8.8.8/8.8.8) id IAA11382 for freebsd-bugs-outgoing; Mon, 7 Sep 1998 08:00:30 -0700 (PDT) (envelope-from owner-freebsd-bugs@FreeBSD.ORG) Received: from freefall.freebsd.org (freefall.FreeBSD.ORG [204.216.27.21]) by hub.freebsd.org (8.8.8/8.8.8) with ESMTP id IAA11287 for ; Mon, 7 Sep 1998 08:00:15 -0700 (PDT) (envelope-from gnats@FreeBSD.org) Received: (from gnats@localhost) by freefall.freebsd.org (8.8.8/8.8.5) id IAA20260; Mon, 7 Sep 1998 08:00:02 -0700 (PDT) Date: Mon, 7 Sep 1998 08:00:02 -0700 (PDT) Message-Id: <199809071500.IAA20260@freefall.freebsd.org> To: freebsd-bugs@FreeBSD.ORG From: Martin Cracauer Subject: Re: bin/7742: fclose(3) dumps core on NULL Reply-To: Martin Cracauer Sender: owner-freebsd-bugs@FreeBSD.ORG Precedence: bulk X-Loop: FreeBSD.org The following reply was made to PR bin/7742; it has been noted by GNATS. From: Martin Cracauer 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 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