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

Miss Islington (bot) webhook-mailer at python.org
Fri Sep 4 18:26:14 EDT 2020


https://github.com/python/cpython/commit/66e9c2aee4af846ab1b77faa8a46fe3a9373d943
commit: 66e9c2aee4af846ab1b77faa8a46fe3a9373d943
branch: 3.8
author: Miss Islington (bot) <31488909+miss-islington at users.noreply.github.com>
committer: GitHub <noreply at github.com>
date: 2020-09-04T15:26:05-07:00
summary:

[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 75c80b0bda89debf312f075716b8c467d411f90e)


Co-authored-by: Tony Solomonik <tony.solomonik at gmail.com>

files:
A Misc/NEWS.d/next/Core and Builtins/2020-08-12-20-29-57.bpo-41533.4pcVAc.rst
M 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
index 0000000000000..e166f0c0b621a
--- /dev/null
+++ b/Misc/NEWS.d/next/Core and Builtins/2020-08-12-20-29-57.bpo-41533.4pcVAc.rst	
@@ -0,0 +1,2 @@
+Free the stack allocated in ``va_build_stack`` if ``do_mkstack`` fails and
+the stack is not a ``small_stack``.
diff --git a/Python/modsupport.c b/Python/modsupport.c
index 7271af3ac5332..506281191c522 100644
--- a/Python/modsupport.c
+++ b/Python/modsupport.c
@@ -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;
     }
 



More information about the Python-checkins mailing list