f0d79ea8be94fa2b4907f16357d6b81008128167 markd Mon Jan 26 11:37:22 2015 -0800 don't flush stdin magic handle on close diff --git src/lib/common.c src/lib/common.c index d231e0b..01c0484 100644 --- src/lib/common.c +++ src/lib/common.c @@ -2751,31 +2751,31 @@ * Return FALSE and print a warning message if there * is a problem.*/ { FILE *f; boolean ok = TRUE; if ((pFile != NULL) && ((f = *pFile) != NULL)) { if (f != stdin && f != stdout) { if (fclose(f) != 0) { errnoWarn("fclose failed"); ok = FALSE; } } - else + else if (f == stdout) { // One expects close() to actually flush the file and close it. If // the file was opened using the magic name "stdout" and then does a // setvbuf(), writes to file, calls carefulClose, then frees the // buffer, the FILE object points to invalid memory. Then the exit() // I/O cleanup causes the invalid memory to be written to the file, // possible outputting corruption data. If would be consistent with // stdio behavior to have "stdout" magic name open "/dev/stdout". fflush(f); } *pFile = NULL; } return ok; }