From mboxrd@z Thu Jan 1 00:00:00 1970 Message-ID: <9702171347.ZM781@davros.bwh.com> Date: Mon, 17 Feb 1997 13:47:49 -0600 From: Bryan W. Headley Subject: Re: fclose() In-Reply-To: On Feb 17, 1:01pm, Richard Henderson wrote: > Subject: Re: fclose() > > fclose(fchan); /* works */ > > fclose(fchan); /* segfaults */ > > Yep. malloc doen't like it when you free the same pointer twice. > > > Ok, so Who's in charge of this code, so I relay my findings? > > Me, I guess. This is a known occurrence. The bug, though, > is with the program trying to fclose twice. The solution of > course is not to do that. > Sometimes you can control that, sometimes you can't. Stupid example: let's say that I, overly-conscientious guy, fclose stdin and stdout and then do an exit(). It's exit's job to close all opened file handles, and naturally it should try to close stdin/stdout. Should exit segv or exit gracefully? The latter. Especially since fclose() should return error code in rather than segv'ing. In professional world, I've seen far too many programs that close all handles at termination, regardless of whether if known that handle is open or not. It WOULD be nice to legislate good programming, I agree... But legacy code rules, especially when practice is "sort of" backed up by API specs. -- 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