Skip to content

Commit 75c80b0

Browse files
authored
closes bpo-41533: Fix a potential memory leak when allocating a stack (pythonGH-21847)
Free the stack allocated in va_build_stack if do_mkstack fails and the stack is not a small_stack
1 parent c68c5af commit 75c80b0

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
@@ -622,6 +622,9 @@ va_build_stack(PyObject **small_stack, Py_ssize_t small_stack_len,
622622
va_end(lva);
623623

624624
if (res < 0) {
625+
if (stack != small_stack) {
626+
PyMem_Free(stack);
627+
}
625628
return NULL;
626629
}
627630

0 commit comments

Comments
 (0)