Red Hat Bugzilla – Bug 6284
fclose(NULL) causes segmentation error
Last modified: 2008-05-01 11:37:52 EDT
When I compile and run the example program shown below, under RedHat Linux 5.2 (Kernel 2.0.36) with gcc (v2.7.2.3), I get a segmentation error. The same code has been run on many other Unix systems and even other versions of Linux without failure. Granted fclose(NULL) is not a useful thing to do, but nevertheless it should not cause a segmentation error. main() { long *file_rep = 0x0; fclose(file_rep); }
This is a programming error. POSIX says that the behavior is unspecified. And glibc segfaults to signal a major error in a program, and it is also withing POSIX's specification.