Skip to content

Commit 66e9c2a

Browse files
[3.8] closes bpo-41533: Fix a potential memory leak when allocating a stack (pythonGH-21847) (pythonGH-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 75c80b0) Co-authored-by: Tony Solomonik <tony.solomonik@gmail.com>
1 parent e52f5bc commit 66e9c2a

File tree

2 files changed

+5
-0
lines changed

2 files changed

+5
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
Free the stack allocated in ``va_build_stack`` if ``do_mkstack`` fails and
2+
the stack is not a ``small_stack``.

Python/modsupport.c

+3
Original file line numberDiff line numberDiff line change
@@ -618,6 +618,9 @@ va_build_stack(PyObject **small_stack, Py_ssize_t small_stack_len,
618618
va_end(lva);
619619

620620
if (res < 0) {
621+
if (stack != small_stack) {
622+
PyMem_Free(stack);
623+
}
621624
return NULL;
622625
}
623626

0 commit comments

Comments
 (0)