From 31b8c2d4380a762d1ed6a7faee74a1d107f86014 Mon Sep 17 00:00:00 2001 From: Roberto Ierusalimschy Date: Wed, 8 Jul 2020 12:02:56 -0300 Subject: Fixed bug of access violation in finalizers Errors in finalizers need a valid 'pc' to produce an error message, even if the error is not propagated. Therefore, calls to the GC (which may call finalizers) inside luaV_execute must save the 'pc'. --- lvm.c | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/lvm.c b/lvm.c index d78d6be2..66d451b0 100644 --- a/lvm.c +++ b/lvm.c @@ -1101,9 +1101,9 @@ void luaV_finishOp (lua_State *L) { /* idem, but without changing the stack */ #define halfProtectNT(exp) (savepc(L), (exp)) - +/* 'c' is the limit of live values in the stack */ #define checkGC(L,c) \ - { luaC_condGC(L, L->top = (c), /* limit of live values */ \ + { luaC_condGC(L, (savepc(L), L->top = (c)), \ updatetrap(ci)); \ luai_threadyield(L); } @@ -1791,8 +1791,7 @@ void luaV_execute (lua_State *L, CallInfo *ci) { vmbreak; } vmcase(OP_VARARGPREP) { - luaT_adjustvarargs(L, GETARG_A(i), ci, cl->p); - updatetrap(ci); + ProtectNT(luaT_adjustvarargs(L, GETARG_A(i), ci, cl->p)); if (trap) { luaD_hookcall(L, ci); L->oldpc = pc + 1; /* next opcode will be seen as a "new" line */ -- cgit v1.2.3-55-g6feb