This is the mail archive of the
libc-hacker@cygnus.com
mailing list for the glibc project.
Re: libio backward compat bug? involving setmntent()
- To: zack@rabi.columbia.edu
- Subject: Re: libio backward compat bug? involving setmntent()
- From: Geoff Keating <geoffk@ozemail.com.au>
- Date: Tue, 4 May 1999 17:10:13 +1000
- CC: drepper@cygnus.com, libc-hacker@cygnus.com
- References: <199905030147.VAA14514@blastula.phys.columbia.edu>
> 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>