aboutsummaryrefslogtreecommitdiff
path: root/lstate.c
diff options
context:
space:
mode:
authorRoberto I <roberto@inf.puc-rio.br>2026-01-11 15:36:03 -0300
committerRoberto I <roberto@inf.puc-rio.br>2026-01-11 15:36:03 -0300
commit2a7cf4f319fc276f4554a8f6364e6b1ba4eb2ded (patch)
treea99a8361664b0adda83186f04e2e9c98afd86b44 /lstate.c
parent5cfc725a8b61a6f96c7324f60ac26739315095ba (diff)
downloadlua-2a7cf4f319fc276f4554a8f6364e6b1ba4eb2ded.tar.gz
lua-2a7cf4f319fc276f4554a8f6364e6b1ba4eb2ded.tar.bz2
lua-2a7cf4f319fc276f4554a8f6364e6b1ba4eb2ded.zip
More effort in avoiding errors in finalizersHEADmaster
Before calling a finalizer, Lua not only checks stack limits, but actually ensures that a minimum number of slots are already allocated for the call. (If it cannot ensure that, it postpones the finalizer.) That avoids finalizers not running due to memory errors that the programmer cannot control.
Diffstat (limited to 'lstate.c')
-rw-r--r--lstate.c17
1 files changed, 11 insertions, 6 deletions
diff --git a/lstate.c b/lstate.c
index 70a11aae..7d341991 100644
--- a/lstate.c
+++ b/lstate.c
@@ -68,14 +68,19 @@ void luaE_setdebt (global_State *g, l_mem debt) {
68} 68}
69 69
70 70
71CallInfo *luaE_extendCI (lua_State *L) { 71CallInfo *luaE_extendCI (lua_State *L, int err) {
72 CallInfo *ci; 72 CallInfo *ci;
73 lua_assert(L->ci->next == NULL); 73 ci = luaM_reallocvector(L, NULL, 0, 1, CallInfo);
74 ci = luaM_new(L, CallInfo); 74 if (l_unlikely(ci == NULL)) { /* allocation failed? */
75 lua_assert(L->ci->next == NULL); 75 if (err)
76 L->ci->next = ci; 76 luaM_error(L); /* raise the error */
77 return NULL; /* else only report it */
78 }
79 ci->next = L->ci->next;
77 ci->previous = L->ci; 80 ci->previous = L->ci;
78 ci->next = NULL; 81 L->ci->next = ci;
82 if (ci->next)
83 ci->next->previous = ci;
79 ci->u.l.trap = 0; 84 ci->u.l.trap = 0;
80 L->nci++; 85 L->nci++;
81 return ci; 86 return ci;