Skip to content

Commit 106c1df

Browse files
closes bpo-41533: Fix a potential memory leak when allocating a stack (GH-21847)
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 8ed1c17 commit 106c1df

File tree

2 files changed

+5
-0
lines changed

2 files changed

+5
-0
lines changed
Lines changed: 2 additions & 0 deletions
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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -619,6 +619,9 @@ va_build_stack(PyObject **small_stack, Py_ssize_t small_stack_len,
619619
va_end(lva);
620620

621621
if (res < 0) {
622+
if (stack != small_stack) {
623+
PyMem_Free(stack);
624+
}
622625
return NULL;
623626
}
624627

0 commit comments

Comments
 (0)