[3.14] GH-141212: Fix possible memory leak in gc_mark_span_push (gh-141213) (gh-141364)

(cherry picked from commit f835552946)

Co-authored-by: Sergey Miryanov <sergey.miryanov@gmail.com>
This commit is contained in:
Miss Islington (bot) 2025-11-10 17:55:01 +01:00 committed by GitHub
parent 63a3737ce7
commit 9f42519431
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View 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;