Skip to content

Commit 8ebeff1

Browse files
committed
Guard ruby_current_vm_ptr is non-null in sigaction
1 parent 52d1df6 commit 8ebeff1

File tree

1 file changed

+7
-0
lines changed

1 file changed

+7
-0
lines changed

ext/stackprof/stackprof.c

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,8 @@
2525
#define FAKE_FRAME_MARK INT2FIX(1)
2626
#define FAKE_FRAME_SWEEP INT2FIX(2)
2727

28+
extern uintptr_t* ruby_current_vm_ptr;
29+
2830
static const char *fake_frame_cstrs[] = {
2931
"(garbage collection)",
3032
"(marking)",
@@ -725,6 +727,11 @@ stackprof_signal_handler(int sig, siginfo_t *sinfo, void *ucontext)
725727

726728
if (!_stackprof.running) return;
727729

730+
// There's a possibility that the signal handler is invoked *after* the Ruby
731+
// VM has been shut down (e.g. after ruby_cleanup(0)). In this case, things
732+
// that rely on global VM state (e.g. rb_during_gc) will segfault.
733+
if (ruby_current_vm_ptr == NULL) return;
734+
728735
if (_stackprof.mode == sym_wall) {
729736
// In "wall" mode, the SIGALRM signal will arrive at an arbitrary thread.
730737
// In order to provide more useful results, especially under threaded web

0 commit comments

Comments
 (0)