]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
closes bpo-41533: Fix a potential memory leak when allocating a stack (GH-21847)
authorTony Solomonik <tony.solomonik@gmail.com>
Sun, 30 Aug 2020 04:53:08 +0000 (07:53 +0300)
committerGitHub <noreply@github.com>
Sun, 30 Aug 2020 04:53:08 +0000 (23:53 -0500)
Free the stack allocated in va_build_stack if do_mkstack fails
and the stack is not a small_stack

Misc/NEWS.d/next/Core and Builtins/2020-08-12-20-29-57.bpo-41533.4pcVAc.rst [new file with mode: 0644]
Python/modsupport.c

diff --git a/Misc/NEWS.d/next/Core and Builtins/2020-08-12-20-29-57.bpo-41533.4pcVAc.rst b/Misc/NEWS.d/next/Core and Builtins/2020-08-12-20-29-57.bpo-41533.4pcVAc.rst
new file mode 100644 (file)
index 0000000..e166f0c
--- /dev/null
@@ -0,0 +1,2 @@
+Free the stack allocated in ``va_build_stack`` if ``do_mkstack`` fails and
+the stack is not a ``small_stack``.
index 2637039d4a1518ce12308cab92ceb9a93e23fd0f..2dabcf383409e9dd86c8e4fb75947b1d697bef8d 100644 (file)
@@ -622,6 +622,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;
     }