diff --git a/gc.c b/gc.c index 41c81efb71ae34..d504b964972d52 100644 --- a/gc.c +++ b/gc.c @@ -4481,7 +4481,8 @@ rb_memerror(void) VALUE exc = GET_VM()->special_exceptions[ruby_error_nomemory]; if (!exc || - rb_ec_raised_p(ec, RAISED_NOMEMORY)) { + rb_ec_raised_p(ec, RAISED_NOMEMORY) || + rb_ec_vm_lock_rec(ec) != ec->tag->lock_rec) { fprintf(stderr, "[FATAL] failed to allocate memory\n"); exit(EXIT_FAILURE); }