aboutsummaryrefslogtreecommitdiff
path: root/ldo.c
diff options
context:
space:
mode:
authorRoberto Ierusalimschy <roberto@inf.puc-rio.br>2021-11-16 14:35:06 -0300
committerRoberto Ierusalimschy <roberto@inf.puc-rio.br>2021-11-16 14:35:06 -0300
commit6b3e116d44eed387aa93126c48eae8a64b38bfc2 (patch)
tree04175aafa7c2ca0d24c41eb3e5115859705bd06f /ldo.c
parente8deac5a41ffd644aaa78fda6d4bd5caa72cb077 (diff)
downloadlua-6b3e116d44eed387aa93126c48eae8a64b38bfc2.tar.gz
lua-6b3e116d44eed387aa93126c48eae8a64b38bfc2.tar.bz2
lua-6b3e116d44eed387aa93126c48eae8a64b38bfc2.zip
Corrected bug in 'luaD_tryfuncTM'
The pointer to the metamethod can be invalidated by a finalizer that can run during a GC in 'checkstackGCp'. (This commit also fixes a detail in the manual.) Bug introduced in commit 91673a8ec.
Diffstat (limited to 'ldo.c')
-rw-r--r--ldo.c3
1 files changed, 2 insertions, 1 deletions
diff --git a/ldo.c b/ldo.c
index 66f89036..f282a773 100644
--- a/ldo.c
+++ b/ldo.c
@@ -388,9 +388,10 @@ static void rethook (lua_State *L, CallInfo *ci, int nres) {
388** an error if there is no '__call' metafield. 388** an error if there is no '__call' metafield.
389*/ 389*/
390StkId luaD_tryfuncTM (lua_State *L, StkId func) { 390StkId luaD_tryfuncTM (lua_State *L, StkId func) {
391 const TValue *tm = luaT_gettmbyobj(L, s2v(func), TM_CALL); 391 const TValue *tm;
392 StkId p; 392 StkId p;
393 checkstackGCp(L, 1, func); /* space for metamethod */ 393 checkstackGCp(L, 1, func); /* space for metamethod */
394 tm = luaT_gettmbyobj(L, s2v(func), TM_CALL); /* (after previous GC) */
394 if (l_unlikely(ttisnil(tm))) 395 if (l_unlikely(ttisnil(tm)))
395 luaG_callerror(L, s2v(func)); /* nothing to call */ 396 luaG_callerror(L, s2v(func)); /* nothing to call */
396 for (p = L->top; p > func; p--) /* open space for metamethod */ 397 for (p = L->top; p > func; p--) /* open space for metamethod */