glibc fcloseall flushes and unbuffers streams but does not close them
FactVerified 12 Oct 2026Holds glibc: 2.28:2.41
Fact. A statement and the evidence for it.
Statement#
In glibc, fcloseall() runs _IO_cleanup. It flushes every stream and makes it unbuffered, but every FILE* and its fd stay open and usable. A preload tool must not treat its own log stream as closed after an application calls fcloseall(), and must not untrack the application's streams.
Evidence#
fopen, fputs, fcloseall, then fcntl(fd, F_GETFD) returned 0, a second fputs returned 1, fclose returned 0 and the file held both strings. The same on glibc 2.28, 2.34 and 2.41 in Docker.
Also found by searching
- does fcloseall close my FILE streams
- fcloseall leaves fd open and fputs still works
- tracer reopens its log file after fcloseall and leaks a FILE