]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
GH-141212: Fix possible memory leak in gc_mark_span_push (gh-141213)
authorSergey Miryanov <sergey.miryanov@gmail.com>
Mon, 10 Nov 2025 16:19:13 +0000 (21:19 +0500)
committerGitHub <noreply@github.com>
Mon, 10 Nov 2025 16:19:13 +0000 (11:19 -0500)
Python/gc_free_threading.c

index f39793c3eeb532a67762e6d40f5ea8223c64bd35..b183062eff795234d22ec32e28f228fcc09d3720 100644 (file)
@@ -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;