[Python-checkins] cpython (2.7): also do not leak the mode string if creating the file fails

benjamin.peterson python-checkins at python.org
Sat Dec 3 16:05:44 EST 2016


https://hg.python.org/cpython/rev/e47e20edafb5
changeset:   105442:e47e20edafb5
branch:      2.7
user:        Benjamin Peterson <benjamin at python.org>
date:        Sat Dec 03 13:05:40 2016 -0800
summary:
  also do not leak the mode string if creating the file fails

files:
  Modules/posixmodule.c |  6 ++++--
  1 files changed, 4 insertions(+), 2 deletions(-)


diff --git a/Modules/posixmodule.c b/Modules/posixmodule.c
--- a/Modules/posixmodule.c
+++ b/Modules/posixmodule.c
@@ -6909,8 +6909,10 @@
     /* 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;
+    if (f == NULL) {
+        PyMEM_FREE(mode);
+        return NULL;
+    }
     Py_BEGIN_ALLOW_THREADS
 #if !defined(MS_WINDOWS) && defined(HAVE_FCNTL_H)
     if (mode[0] == 'a') {

-- 
Repository URL: https://hg.python.org/cpython


More information about the Python-checkins mailing list