summaryrefslogtreecommitdiff
path: root/vm_backtrace.c
diff options
context:
space:
mode:
Diffstat (limited to 'vm_backtrace.c')
-rw-r--r--vm_backtrace.c9
1 files changed, 9 insertions, 0 deletions
diff --git a/vm_backtrace.c b/vm_backtrace.c
index 6e38224a91..e50611c7bb 100644
--- a/vm_backtrace.c
+++ b/vm_backtrace.c
@@ -1580,6 +1580,15 @@ rb_profile_frames(int start, int limit, VALUE *buff, int *lines)
const rb_control_frame_t *cfp = ec->cfp, *end_cfp = RUBY_VM_END_CONTROL_FRAME(ec);
const rb_callable_method_entry_t *cme;
+ // If this function is called inside a thread after thread creation, but
+ // before the CFP has been created, just return 0. This can happen when
+ // sampling via signals. Threads can be interrupted randomly by the
+ // signal, including during the time after the thread has been created, but
+ // before the CFP has been allocated
+ if (!cfp) {
+ return 0;
+ }
+
// Skip dummy frame; see `rb_ec_partial_backtrace_object` for details
end_cfp = RUBY_VM_NEXT_CONTROL_FRAME(end_cfp);