From a82a3533e64cf1d9767d702dd7173d09dbbb6794 Mon Sep 17 00:00:00 2001 From: dearblue Date: Sat, 30 Jul 2022 22:32:02 +0900 Subject: [PATCH] Fix `SIGSEGV` caused by GC during fiber initialization GC may occur in the `c->stbase = mrb_malloc()` part of the `fiber_init()` function. The `SIGSEGV` happens because it references the `c->ci->stack` field without checking `c->ci`. This is caused by #5272. --- src/gc.c | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/src/gc.c b/src/gc.c index 4f55dc6ae..31492495b 100644 --- a/src/gc.c +++ b/src/gc.c @@ -1020,13 +1020,11 @@ gc_gray_counts(mrb_state *mrb, mrb_gc *gc, struct RBasic *obj) mrb_callinfo *ci; if (!c || c->status == MRB_FIBER_TERMINATED) break; + if (!c->ci) break; /* mark stack */ i = c->ci->stack - c->stbase; - - if (c->ci) { - i += mrb_ci_nregs(c->ci); - } + i += mrb_ci_nregs(c->ci); if (c->stbase + i > c->stend) i = c->stend - c->stbase; children += i;