bug-glibc
[Top][All Lists]
Advanced

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

freopen file descriptor leak?


From: Oswald Buddenhagen
Subject: freopen file descriptor leak?
Date: Sun, 14 Apr 2002 14:22:02 +0200
User-agent: Mutt/1.3.28i

glibc 2.2.5
sysd-stdio.c: __stdio_reopen
a new file descriptor is opened (newcookie) and is dup2()ed to the old
descriptor (*cookieptr), but is not closed afterwards. bug?

why i looked at the code at all ... i'm trying to find out, if it is
possible to freopen std{out,err}, when they were not open at program
startup.
i produced something like this and it seems to work with glibc:
        if (stderr)
            fclose (stderr);
        if ((fd = open (errf, O_CREAT | O_APPEND | O_WRONLY, 0666)) < 0)
            LogError ("Cannot open log file %s\n", errf);
        else
            if (fd != 2) {
                dup2 (fd, 2);
                close (fd);
            }
        stderr = fdopen (2, "a");
however, for example on freebsd this fails miserably, as stderr is #defined 
as (&_sfd[2]) or something like that. now i'm wondering, what a portable
solution may look like?

greetings

-- 
Hi! I'm a .signature virus! Copy me into your ~/.signature, please!
--
The problem with making software idiot-proof is that idiots are so clever.



reply via email to

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