summaryrefslogtreecommitdiff
path: root/gc.c
diff options
context:
space:
mode:
authorKJ Tsanaktsidis <ktsanaktsidis@zendesk.com>2022-01-08 15:21:46 +1100
committerJean Boussier <jean.boussier@gmail.com>2023-03-09 09:46:14 +0100
commit7bd7aee02e303de27d2cddfc5ef47e612d6782cb (patch)
tree6a99218d99f8e2b21235d0d3e473b40e3268fef2 /gc.c
parent1a0d3ec4b9bfca2c06abc2909dd1dd15308943fb (diff)
Fix interpreter crash caused by RUBY_INTERNAL_EVENT_NEWOBJ + Ractors
When a Ractor is created whilst a tracepoint for RUBY_INTERNAL_EVENT_NEWOBJ is active, the interpreter crashes. This is because during the early setup of the Ractor, the stdio objects are created, which allocates Ruby objects, which fires the tracepoint. However, the tracepoint machinery tries to dereference the control frame (ec->cfp->pc), which isn't set up yet and so crashes with a null pointer dereference. Fix this by not firing GC tracepoints if cfp isn't yet set up.
Notes
Notes: Merged: https://github.com/ruby/ruby/pull/5990
Diffstat (limited to 'gc.c')
-rw-r--r--gc.c1
1 files changed, 1 insertions, 0 deletions
diff --git a/gc.c b/gc.c
index 31a5788297..b8c8ae099d 100644
--- a/gc.c
+++ b/gc.c
@@ -2484,6 +2484,7 @@ rb_objspace_set_event_hook(const rb_event_flag_t event)
static void
gc_event_hook_body(rb_execution_context_t *ec, rb_objspace_t *objspace, const rb_event_flag_t event, VALUE data)
{
+ if (UNLIKELY(!ec->cfp)) return;
const VALUE *pc = ec->cfp->pc;
if (pc && VM_FRAME_RUBYFRAME_P(ec->cfp)) {
int prev_opcode = rb_vm_insn_addr2opcode((void *)*ec->cfp->iseq->body->iseq_encoded);