[3.8] closes bpo-41533: Fix a potential memory leak when allocating a stack (GH-21847) (GH-22015)

Free the stack allocated in va_build_stack if do_mkstack fails
and the stack is not a small_stack
(cherry picked from commit 75c80b0bda)


Co-authored-by: Tony Solomonik <tony.solomonik@gmail.com>
This commit is contained in:
Miss Islington (bot) 2020-09-04 15:26:05 -07:00 committed by GitHub
parent e52f5bc898
commit 66e9c2aee4
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 5 additions and 0 deletions

View File

@ -0,0 +1,2 @@
Free the stack allocated in ``va_build_stack`` if ``do_mkstack`` fails and
the stack is not a ``small_stack``.

View File

@ -618,6 +618,9 @@ va_build_stack(PyObject **small_stack, Py_ssize_t small_stack_len,
va_end(lva);
if (res < 0) {
if (stack != small_stack) {
PyMem_Free(stack);
}
return NULL;
}