Skip to content

Commit edfcbac

Browse files
luke-gruberk0kubun
authored andcommitted
thread_cleanup: set CFP to NULL before clearing ec's stack
We clear the CFP first so that if a sampling profiler interrupts the current thread during `rb_ec_set_vm_stack`, `thread_profile_frames` returns early instead of trying to walk the stack that's no longer set on the ec. The early return in `thread_profile_frames` was introduced at eab7f46. Fixes [Bug #21441]
1 parent c57efbf commit edfcbac

File tree

1 file changed

+3
-3
lines changed

1 file changed

+3
-3
lines changed

vm.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3618,10 +3618,10 @@ rb_ec_initialize_vm_stack(rb_execution_context_t *ec, VALUE *stack, size_t size)
36183618
void
36193619
rb_ec_clear_vm_stack(rb_execution_context_t *ec)
36203620
{
3621-
rb_ec_set_vm_stack(ec, NULL, 0);
3622-
3623-
// Avoid dangling pointers:
3621+
// set cfp to NULL before clearing the stack in case `thread_profile_frames`
3622+
// gets called in this middle of `rb_ec_set_vm_stack` via signal handler.
36243623
ec->cfp = NULL;
3624+
rb_ec_set_vm_stack(ec, NULL, 0);
36253625
}
36263626

36273627
static void

0 commit comments

Comments
 (0)