summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorBenjamin Peterson <benjamin@python.org>2016-12-03 21:03:18 (GMT)
committerBenjamin Peterson <benjamin@python.org>2016-12-03 21:03:18 (GMT)
commitd3035d5d3da11b464580ee2a49c6fcf0d23f0252 (patch)
treeb4ab2c88e891e8665414d5d433de7283410ac65e
parentcadd22f2f53c739aabf363ea25bddae6039a60f7 (diff)
downloadcpython-d3035d5d3da11b464580ee2a49c6fcf0d23f0252.zip
cpython-d3035d5d3da11b464580ee2a49c6fcf0d23f0252.tar.gz
cpython-d3035d5d3da11b464580ee2a49c6fcf0d23f0252.tar.bz2
do not leak the FILE * pointer in error cases of fdopen()
-rw-r--r--Modules/posixmodule.c14
1 files changed, 8 insertions, 6 deletions
diff --git a/Modules/posixmodule.c b/Modules/posixmodule.c
index 72bf7d2..12f6bc0 100644
--- a/Modules/posixmodule.c
+++ b/Modules/posixmodule.c
@@ -6906,6 +6906,11 @@ posix_fdopen(PyObject *self, PyObject *args)
}
}
#endif
+ /* The dummy filename used here must be kept in sync with the value
+ tested against in gzip.GzipFile.__init__() - see issue #13781. */
+ f = PyFile_FromFile(NULL, "<fdopen>", orgmode, fclose);
+ if (f == NULL)
+ return NULL;
Py_BEGIN_ALLOW_THREADS
#if !defined(MS_WINDOWS) && defined(HAVE_FCNTL_H)
if (mode[0] == 'a') {
@@ -6926,13 +6931,10 @@ posix_fdopen(PyObject *self, PyObject *args)
#endif
Py_END_ALLOW_THREADS
PyMem_FREE(mode);
- if (fp == NULL)
+ if (fp == NULL) {
+ Py_DECREF(f);
return posix_error();
- /* The dummy filename used here must be kept in sync with the value
- tested against in gzip.GzipFile.__init__() - see issue #13781. */
- f = PyFile_FromFile(NULL, "<fdopen>", orgmode, fclose);
- if (f == NULL)
- return NULL;
+ }
/* We now know we will succeed, so initialize the file object. */
((PyFileObject *)f)->f_fp = fp;
PyFile_SetBufSize(f, bufsize);