]> granicus.if.org Git - python/commitdiff
_winconsoleio: Fix memory leak (#2485)
authorVictor Stinner <victor.stinner@gmail.com>
Thu, 29 Jun 2017 08:53:34 +0000 (10:53 +0200)
committerGitHub <noreply@github.com>
Thu, 29 Jun 2017 08:53:34 +0000 (10:53 +0200)
Fix memory leak when _winconsoleio tries to open a non-console file:
free the name buffer.

Modules/_io/winconsoleio.c

index 346c38637f9e1b410c8b664a42146a3308d2b1c1..5cf3f070d8252621d7c71910926bc0a8068f6d4a 100644 (file)
@@ -317,6 +317,7 @@ _io__WindowsConsoleIO___init___impl(winconsoleio *self, PyObject *nameobj,
         if (name == NULL)
             return -1;
         if (console_type == '\0') {
+            PyMem_Free(name);
             PyErr_SetString(PyExc_ValueError,
                 "Cannot open non-console file");
             return -1;
@@ -400,7 +401,7 @@ _io__WindowsConsoleIO___init___impl(winconsoleio *self, PyObject *nameobj,
         PyErr_SetString(PyExc_ValueError,
             "Cannot open non-console file");
         goto error;
-    }    
+    }
     if (self->writable && console_type != 'w') {
         PyErr_SetString(PyExc_ValueError,
             "Cannot open console input buffer for writing");
@@ -428,8 +429,7 @@ error:
     internal_close(self);
 
 done:
-    if (name)
-        PyMem_Free(name);
+    PyMem_Free(name);
     return ret;
 }