about summary refs log tree commit diff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/stdio/tmpfile.c3
1 files changed, 2 insertions, 1 deletions
diff --git a/src/stdio/tmpfile.c b/src/stdio/tmpfile.c
index a7d0000a..525090aa 100644
--- a/src/stdio/tmpfile.c
+++ b/src/stdio/tmpfile.c
@@ -16,12 +16,13 @@ FILE *tmpfile(void)
 		__randname(s+13);
 		fd = sys_open(s, O_RDWR|O_CREAT|O_EXCL, 0600);
 		if (fd >= 0) {
-			f = __fdopen(fd, "w+");
 #ifdef SYS_unlink
 			__syscall(SYS_unlink, s);
 #else
 			__syscall(SYS_unlinkat, AT_FDCWD, s, 0);
 #endif
+			f = __fdopen(fd, "w+");
+			if (!f) __syscall(SYS_close, fd);
 			return f;
 		}
 	}