From 9b2893ed61ad38d3877d082b2c72df0537a3ffe0 Mon Sep 17 00:00:00 2001 From: Matt Valentine-House Date: Wed, 18 Dec 2024 22:10:04 +0000 Subject: [PATCH] Memerror is fatal if VM cannot be unlocked. [Bug #20942] If we've raised a memerror while the VM is locked, and the tag we're jumping to has been locked at a different level to the current lock (ie. we've locked the VM again since the tag we're jumping to) then we should consider this memerror fatal and exit, since the tag cannot unlock the VM. Co-Authored-By: Peter Zhu --- gc.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/gc.c b/gc.c index 4c32c5a1ed49f4..93dd58e0ead867 100644 --- a/gc.c +++ b/gc.c @@ -4460,7 +4460,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); }