From cde931dd6cab4d17c7d61ad1d00a959b57b62ebd Mon Sep 17 00:00:00 2001 From: Ken Jin <28750310+Fidget-Spinner@users.noreply.github.com> Date: Wed, 3 Jul 2024 21:23:16 +0800 Subject: [PATCH] don't deref NULL --- Python/gc_free_threading.c | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/Python/gc_free_threading.c b/Python/gc_free_threading.c index 12d27b16aee445..5392e70caf8b2c 100644 --- a/Python/gc_free_threading.c +++ b/Python/gc_free_threading.c @@ -324,8 +324,11 @@ gc_visit_thread_stacks(PyInterpreterState *interp) _PyInterpreterFrame *curr_frame = p->current_frame; while (curr_frame != NULL) { PyCodeObject *co = (PyCodeObject *)curr_frame->f_executable; - for (int i = 0; i < co->co_nlocalsplus + co->co_stacksize; i++) { - gc_visit_stackref(curr_frame->localsplus[i]); + if (co != NULL && PyCode_Check(co)) { + for (int i = 0; + i < co->co_nlocalsplus + co->co_stacksize; i++) { + gc_visit_stackref(curr_frame->localsplus[i]); + } } curr_frame = curr_frame->previous; } @@ -585,14 +588,14 @@ deduce_unreachable_heap(PyInterpreterState *interp, // incoming references. gc_visit_heaps(interp, &update_refs, &state->base); - gc_visit_thread_stacks(interp); - #ifdef GC_DEBUG // Check that all objects are marked as unreachable and that the computed // reference count difference (stored in `ob_tid`) is non-negative. gc_visit_heaps(interp, &validate_gc_objects, &state->base); #endif + gc_visit_thread_stacks(interp); + // Transitively mark reachable objects by clearing the // _PyGC_BITS_UNREACHABLE flag. if (gc_visit_heaps(interp, &mark_heap_visitor, &state->base) < 0) {