Skip to content

Commit cde931d

Browse files
don't deref NULL
1 parent 700c2fd commit cde931d

File tree

1 file changed

+7
-4
lines changed

1 file changed

+7
-4
lines changed

Python/gc_free_threading.c

+7-4
Original file line numberDiff line numberDiff line change
@@ -324,8 +324,11 @@ gc_visit_thread_stacks(PyInterpreterState *interp)
324324
_PyInterpreterFrame *curr_frame = p->current_frame;
325325
while (curr_frame != NULL) {
326326
PyCodeObject *co = (PyCodeObject *)curr_frame->f_executable;
327-
for (int i = 0; i < co->co_nlocalsplus + co->co_stacksize; i++) {
328-
gc_visit_stackref(curr_frame->localsplus[i]);
327+
if (co != NULL && PyCode_Check(co)) {
328+
for (int i = 0;
329+
i < co->co_nlocalsplus + co->co_stacksize; i++) {
330+
gc_visit_stackref(curr_frame->localsplus[i]);
331+
}
329332
}
330333
curr_frame = curr_frame->previous;
331334
}
@@ -585,14 +588,14 @@ deduce_unreachable_heap(PyInterpreterState *interp,
585588
// incoming references.
586589
gc_visit_heaps(interp, &update_refs, &state->base);
587590

588-
gc_visit_thread_stacks(interp);
589-
590591
#ifdef GC_DEBUG
591592
// Check that all objects are marked as unreachable and that the computed
592593
// reference count difference (stored in `ob_tid`) is non-negative.
593594
gc_visit_heaps(interp, &validate_gc_objects, &state->base);
594595
#endif
595596

597+
gc_visit_thread_stacks(interp);
598+
596599
// Transitively mark reachable objects by clearing the
597600
// _PyGC_BITS_UNREACHABLE flag.
598601
if (gc_visit_heaps(interp, &mark_heap_visitor, &state->base) < 0) {

0 commit comments

Comments
 (0)