Skip to content

Commit d8e1279

Browse files
committed
Add close()
1 parent a3ded44 commit d8e1279

1 file changed

Lines changed: 9 additions & 0 deletions

File tree

Python/fileutils.c

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
# include "pycore_fileutils_windows.h" // FILE_STAT_BASIC_INFORMATION
1717
# define fdopen _fdopen
1818
# define dup _dup
19+
# define close _close
1920
# if defined(MS_WINDOWS_GAMES) && !defined(MS_WINDOWS_DESKTOP)
2021
# define PATHCCH_ALLOW_LONG_PATHS 0x01
2122
# else
@@ -2065,12 +2066,20 @@ int
20652066
_Py_fdprintf(int fd, const char *fmt, ...)
20662067
{
20672068
int newfd = dup(fd);
2069+
if (newfd < 0) {
2070+
return -1;
2071+
}
20682072
FILE *handle = fdopen(newfd, "a");
2073+
if (handle == NULL) {
2074+
close(newfd);
2075+
return -1;
2076+
}
20692077
va_list vargs;
20702078
va_start(vargs, fmt);
20712079
int res = vfprintf(handle, fmt, vargs);
20722080
va_end(vargs);
20732081
fclose(handle);
2082+
close(newfd);
20742083
if (res != 0) {
20752084
return -1;
20762085
}

0 commit comments

Comments
 (0)