diff --git a/src/files.c b/src/files.c index 26d8281b..65780c27 100644 --- a/src/files.c +++ b/src/files.c @@ -1469,13 +1469,15 @@ char *safe_tempfile(FILE **stream) fd = mkstemp(tempfile_name); - if (fd == -1) { + *stream = (fd > 0) ? fdopen(fd, "r+b") : NULL; + + if (*stream == NULL) { + if (fd > 0) + close(fd); free(tempfile_name); return NULL; } - *stream = fdopen(fd, "r+b"); - return tempfile_name; }