Unverified Kaydet (Commit) 463b82a3 authored tarafından Victor Stinner's avatar Victor Stinner Kaydeden (comit) GitHub

bpo-36763: Fix Py_SetStandardStreamEncoding() (GH-13028)

Fix memory leak in Py_SetStandardStreamEncoding(): release memory
if the function is called twice.
üst 0df635c7
Fix memory leak in :c:func:`Py_SetStandardStreamEncoding`: release memory if
the function is called twice.
...@@ -375,6 +375,7 @@ Py_SetStandardStreamEncoding(const char *encoding, const char *errors) ...@@ -375,6 +375,7 @@ Py_SetStandardStreamEncoding(const char *encoding, const char *errors)
* Py_Initialize hasn't been called yet. * Py_Initialize hasn't been called yet.
*/ */
if (encoding) { if (encoding) {
PyMem_RawFree(_Py_StandardStreamEncoding);
_Py_StandardStreamEncoding = _PyMem_RawStrdup(encoding); _Py_StandardStreamEncoding = _PyMem_RawStrdup(encoding);
if (!_Py_StandardStreamEncoding) { if (!_Py_StandardStreamEncoding) {
res = -2; res = -2;
...@@ -382,11 +383,11 @@ Py_SetStandardStreamEncoding(const char *encoding, const char *errors) ...@@ -382,11 +383,11 @@ Py_SetStandardStreamEncoding(const char *encoding, const char *errors)
} }
} }
if (errors) { if (errors) {
PyMem_RawFree(_Py_StandardStreamErrors);
_Py_StandardStreamErrors = _PyMem_RawStrdup(errors); _Py_StandardStreamErrors = _PyMem_RawStrdup(errors);
if (!_Py_StandardStreamErrors) { if (!_Py_StandardStreamErrors) {
if (_Py_StandardStreamEncoding) {
PyMem_RawFree(_Py_StandardStreamEncoding); PyMem_RawFree(_Py_StandardStreamEncoding);
} _Py_StandardStreamEncoding = NULL;
res = -3; res = -3;
goto done; goto done;
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment