Calling fflush(0) in a multi-threaded application can crash it. I will attach a program that can reproduce this problem; I've tried it on both Red Hat Linux v6.2 and v7.1, both fully updated, both dual Pentium 3 machines. By inspecting the GNU libc code, it seems no locking is done in the _IO_flush_all() call, so I guess closing a file during fflush(0) can break the list-iteration done in that function. The attached example crashes much faster on the v7.1 machine (which is also faster); the v7.1 is updated vanilla, the v6.2 one uses GCC v2.95.3 as compiler. On the v7.1 machine, it crashes in a few seconds, on the 6.2 machine, it can take a few minutes before it crashes. All crashes are SIGSEGV. I know ISO C does not say anything about thread safety in the IO library, but GNU libio/libc seems to be implemented with thread safety in mind.
Created attachment 22086 [details] Threaded fflush(0) example code
Should be fixed in glibc-2.2.3-17. At least I run the test for more than an hour without any problems.
Jakub, I think this bug can be closed -- it has worked correctly for ages now ;-)