new cheesy test by Denis Vlasenko to trigger fclose loop
authorMike Frysinger <vapier@gentoo.org>
Mon, 5 Feb 2007 01:17:09 +0000 (01:17 -0000)
committerMike Frysinger <vapier@gentoo.org>
Mon, 5 Feb 2007 01:17:09 +0000 (01:17 -0000)
test/stdio/fclose-loop.c [new file with mode: 0644]

diff --git a/test/stdio/fclose-loop.c b/test/stdio/fclose-loop.c
new file mode 100644 (file)
index 0000000..fc0cc42
--- /dev/null
@@ -0,0 +1,21 @@
+/* From: Denis Vlasenko <vda.linux@googlemail.com>
+ *     With certain combination of .config options fclose() does not
+ *     remove FILE* pointer from _stdio_openlist.  As a result, subsequent
+ *     fopen() may allocate new FILE structure exactly in place of one
+ *     freed by previous fclose(), which then makes _stdio_openlist
+ *     circularlt looped. The following program will enter infinite loop
+ *     trying to walk _stdio_openlist in exit():
+ */
+
+#include <stdlib.h>
+#include <stdio.h>
+
+int main(int argc, char *argv[])
+{
+       FILE* fp;
+       fp = fopen("/dev/null", "r");
+       fclose(fp);
+       fp = fopen("/dev/zero", "r");
+       fclose(fp);
+       return 0;
+}