bug-glibc
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: fdopen() leaks badly when multithreaded


From: Gurusamy Sarathy
Subject: Re: fdopen() leaks badly when multithreaded
Date: Fri, 15 Mar 2002 08:43:33 -0800

On Fri, 15 Mar 2002 16:06:46 +0100, Wolfram Gloger wrote:
>> This short program demonstrates a fairly serious problem with
>> fdopen() when used in a multi-threaded application.  The real
>> application from which I condensed this actually segfaults, but
>> this variant only seems to leak.  I've attached the output when
>> running it under the glibc 2.2.4 that's in RedHat 7.2, and
>
>Yep, I can reproduce this with glibc-2.2.5, too.  Basically, there
>seems to be a peculiar failure path inside libio where the allocated
>buffer isn't freed.  At the moment I can't see anything
>thread-specific about this, although it is the multiple threads that
>cause the fdopen() to fail occasionally (which I find perplexing, but
>that is a different issue..).

BTW (in case other people are hit by the same issue) I can think of
two workarounds:

  * Set fdopened_fp->_fileno to -1 before fclose()ing it if the
    underlying fileno is shared with another FILE that will also
    be closed (this hack relies on the internals of the FILE structure
    remaining the way they are, and cannot be called a decent
    long-term workaround)
  * Only fdopen() unique fds that noone else owns or will close().
    IOW, do fdopen(dup(fd),...) if fd is shared with some other FILE.
    Can anyone see any problems with this approach?

>I'm working on a patch, but I have to get myself a bit more acquainted
>with libio first.

Thanks,


Sarathy
address@hidden



reply via email to

[Prev in Thread] Current Thread [Next in Thread]