From: Miss Islington (bot) <31488909+miss-islington@users.noreply.github.com> Date: Mon, 10 Nov 2025 16:55:01 +0000 (+0100) Subject: [3.14] GH-141212: Fix possible memory leak in gc_mark_span_push (gh-141213) (gh-141364) X-Git-Tag: v3.14.1~159 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=9f425194318e0c11e60f1b1144d5ee902c58ba60;p=thirdparty%2FPython%2Fcpython.git [3.14] GH-141212: Fix possible memory leak in gc_mark_span_push (gh-141213) (gh-141364) (cherry picked from commit f835552946e29ec20144c359b8822f9e421d4d64) Co-authored-by: Sergey Miryanov --- diff --git a/Python/gc_free_threading.c b/Python/gc_free_threading.c index 5aaa68c5b51f..94c77991f5f4 100644 --- a/Python/gc_free_threading.c +++ b/Python/gc_free_threading.c @@ -675,10 +675,11 @@ gc_mark_span_push(gc_span_stack_t *ss, PyObject **start, PyObject **end) else { ss->capacity *= 2; } - ss->stack = (gc_span_t *)PyMem_Realloc(ss->stack, ss->capacity * sizeof(gc_span_t)); - if (ss->stack == NULL) { + gc_span_t *new_stack = (gc_span_t *)PyMem_Realloc(ss->stack, ss->capacity * sizeof(gc_span_t)); + if (new_stack == NULL) { return -1; } + ss->stack = new_stack; } assert(end > start); ss->stack[ss->size].start = start;