This is the mail archive of the libc-hacker@cygnus.com mailing list for the glibc project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

Re: libio backward compat bug? involving setmntent()


> cc: libc-hacker@cygnus.com
> Date: Sun, 02 May 1999 21:47:58 -0400
> From: Zack Weinberg <zack@rabi.columbia.edu>
> 
> On 02 May 1999 18:35:12 -0700, Ulrich Drepper wrote:
> >Zack Weinberg <zack@rabi.columbia.edu> writes:
> >
> >> The appended slightly-out-of-spec code segfaults when compiled on a
> >> libc 2.0 system and run on a libc 2.1 system.  The problem is that
> >> setmntent() returns a new FILE*, but fclose is bound to the old
> >> fclose.
> >> 
> >> Do we want to support this, and if so, how?  (Have old fclose
> >> recognize when it's handed a new FILE* and call _IO_new_fclose?)
> >
> >There is no libc problem (at least, not really).  The program is
> >wrong:
> 
> I know the program is wrong.  However, it appears to work, and
> recompiling it makes it appear to work again - so we get nailed for
> inadequate backward compat.
...

Whether or not we make it work, we should mention this in the FAQ.

Something like:

Q: My program segfaults when I call fclose() on the FILE* returned
   from setmntent().  Is this a glibc bug?

A: No.  Don't do this.  Use endmntent(), that's what it's for.

   In general, you should use the correct deallocation routine.  For
   instance, if you open a file using fopen(), you should deallocate
   the FILE * using fclose(), not free(), even though the FILE * is
   also a pointer.

   In the case of setmntent(), it may appear to work in most cases,
   but it won't always work.  Unfortunately, for compatibility
   reasons, we can't change the return type of setmntent() to
   something other than FILE *.

-- 
Geoffrey Keating <geoffk@ozemail.com.au>


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]