Skip to content

Commit

Permalink
Guard ruby_current_vm_ptr is non-null in sigaction
Browse files Browse the repository at this point in the history
  • Loading branch information
ianks committed Mar 16, 2023
1 parent 52d1df6 commit b9e762e
Showing 1 changed file with 7 additions and 0 deletions.
7 changes: 7 additions & 0 deletions ext/stackprof/stackprof.c
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@
#define FAKE_FRAME_MARK INT2FIX(1)
#define FAKE_FRAME_SWEEP INT2FIX(2)

extern void* ruby_current_vm_ptr;

static const char *fake_frame_cstrs[] = {
"(garbage collection)",
"(marking)",
Expand Down Expand Up @@ -725,6 +727,11 @@ stackprof_signal_handler(int sig, siginfo_t *sinfo, void *ucontext)

if (!_stackprof.running) return;

// There's a possibility that the signal handler is invoked *after* the Ruby
// VM has been shut down (e.g. after ruby_cleanup(0)). In this case, things
// that rely on global VM state (e.g. rb_during_gc) will segfault.
if (ruby_current_vm_ptr == NULL) return;

if (_stackprof.mode == sym_wall) {
// In "wall" mode, the SIGALRM signal will arrive at an arbitrary thread.
// In order to provide more useful results, especially under threaded web
Expand Down

0 comments on commit b9e762e

Please sign in to comment.