summaryrefslogtreecommitdiffstats
path: root/Modules/_io
diff options
context:
space:
mode:
authorVictor Stinner <victor.stinner@gmail.com>2017-06-29 08:53:34 (GMT)
committerGitHub <noreply@github.com>2017-06-29 08:53:34 (GMT)
commit1d56ed5210babb68b5798cd943bb21f417e781ee (patch)
treebb5a847d67170f1c00f5663b97121bb49995ca2d /Modules/_io
parentb78fbaaeab9df8cfbbdae3d5faf2d1537d73e43b (diff)
downloadcpython-1d56ed5210babb68b5798cd943bb21f417e781ee.zip
cpython-1d56ed5210babb68b5798cd943bb21f417e781ee.tar.gz
cpython-1d56ed5210babb68b5798cd943bb21f417e781ee.tar.bz2
_winconsoleio: Fix memory leak (#2485)
Fix memory leak when _winconsoleio tries to open a non-console file: free the name buffer.
Diffstat (limited to 'Modules/_io')
-rw-r--r--Modules/_io/winconsoleio.c6
1 files changed, 3 insertions, 3 deletions
diff --git a/Modules/_io/winconsoleio.c b/Modules/_io/winconsoleio.c
index 346c386..5cf3f07 100644
--- a/Modules/_io/winconsoleio.c
+++ b/Modules/_io/winconsoleio.c
@@ -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;
}