fclose-loop.c 624 B

123456789101112131415161718192021
  1. /* From: Denis Vlasenko <vda.linux@googlemail.com>
  2. * With certain combination of .config options fclose() does not
  3. * remove FILE* pointer from _stdio_openlist. As a result, subsequent
  4. * fopen() may allocate new FILE structure exactly in place of one
  5. * freed by previous fclose(), which then makes _stdio_openlist
  6. * circularlt looped. The following program will enter infinite loop
  7. * trying to walk _stdio_openlist in exit():
  8. */
  9. #include <stdlib.h>
  10. #include <stdio.h>
  11. int main(int argc, char *argv[])
  12. {
  13. FILE* fp;
  14. fp = fopen("/dev/null", "r");
  15. fclose(fp);
  16. fp = fopen("/dev/zero", "r");
  17. fclose(fp);
  18. return 0;
  19. }