From: Benjamin Peterson Date: Sat, 3 Dec 2016 19:12:51 +0000 (-0800) Subject: fix refleak in file handle creation error case X-Git-Tag: v2.7.13rc1~6 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=ada7d9291783b8df9d49ca3cf722dd7537f9358f;p=python fix refleak in file handle creation error case --- diff --git a/Modules/posixmodule.c b/Modules/posixmodule.c index df3c326714..72bf7d206c 100644 --- a/Modules/posixmodule.c +++ b/Modules/posixmodule.c @@ -6906,13 +6906,6 @@ 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, "", orgmode, fclose); - if (f == NULL) { - PyMem_FREE(mode); - return NULL; - } Py_BEGIN_ALLOW_THREADS #if !defined(MS_WINDOWS) && defined(HAVE_FCNTL_H) if (mode[0] == 'a') { @@ -6935,6 +6928,11 @@ posix_fdopen(PyObject *self, PyObject *args) PyMem_FREE(mode); if (fp == NULL) 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, "", 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);