_winconsoleio: Fix memory leak (#2485)

Fix memory leak when _winconsoleio tries to open a non-console file:
free the name buffer.
This commit is contained in:
Victor Stinner 2017-06-29 10:53:34 +02:00 committed by GitHub
parent b78fbaaeab
commit 1d56ed5210

View file

@ -317,6 +317,7 @@ _io__WindowsConsoleIO___init___impl(winconsoleio *self, PyObject *nameobj,
if (name == NULL) if (name == NULL)
return -1; return -1;
if (console_type == '\0') { if (console_type == '\0') {
PyMem_Free(name);
PyErr_SetString(PyExc_ValueError, PyErr_SetString(PyExc_ValueError,
"Cannot open non-console file"); "Cannot open non-console file");
return -1; return -1;
@ -428,8 +429,7 @@ error:
internal_close(self); internal_close(self);
done: done:
if (name) PyMem_Free(name);
PyMem_Free(name);
return ret; return ret;
} }