aboutsummaryrefslogtreecommitdiff
path: root/lgc.c
diff options
context:
space:
mode:
authorRoberto Ierusalimschy <roberto@inf.puc-rio.br>2019-06-21 09:34:49 -0300
committerRoberto Ierusalimschy <roberto@inf.puc-rio.br>2019-06-21 09:34:49 -0300
commit1d70708a784980bfeee142d3ed95f8df9e1b1a4a (patch)
treeef00a344292e5631786eeaabe704534188726476 /lgc.c
parentbe73f72fcc944a8ebae2c60d2ce84139acb011b9 (diff)
downloadlua-1d70708a784980bfeee142d3ed95f8df9e1b1a4a.tar.gz
lua-1d70708a784980bfeee142d3ed95f8df9e1b1a4a.tar.bz2
lua-1d70708a784980bfeee142d3ed95f8df9e1b1a4a.zip
Fixed bug [5.4 alpha] for errors in finalizers
Fixes the bug related in [1] (Lua can crash after raising an error in a finalizer), following the lead in [2]. [1] http://lua-users.org/lists/lua-l/2019-06/msg00448.html [2] http://lua-users.org/lists/lua-l/2019-06/msg00450.html
Diffstat (limited to 'lgc.c')
-rw-r--r--lgc.c8
1 files changed, 4 insertions, 4 deletions
diff --git a/lgc.c b/lgc.c
index 69d8a186..8444566c 100644
--- a/lgc.c
+++ b/lgc.c
@@ -838,21 +838,21 @@ static void GCTM (lua_State *L) {
838 int running = g->gcrunning; 838 int running = g->gcrunning;
839 L->allowhook = 0; /* stop debug hooks during GC metamethod */ 839 L->allowhook = 0; /* stop debug hooks during GC metamethod */
840 g->gcrunning = 0; /* avoid GC steps */ 840 g->gcrunning = 0; /* avoid GC steps */
841 setobj2s(L, L->top, tm); /* push finalizer... */ 841 setobj2s(L, L->top++, tm); /* push finalizer... */
842 setobj2s(L, L->top + 1, &v); /* ... and its argument */ 842 setobj2s(L, L->top++, &v); /* ... and its argument */
843 L->top += 2; /* and (next line) call the finalizer */
844 L->ci->callstatus |= CIST_FIN; /* will run a finalizer */ 843 L->ci->callstatus |= CIST_FIN; /* will run a finalizer */
845 status = luaD_pcall(L, dothecall, NULL, savestack(L, L->top - 2), 0); 844 status = luaD_pcall(L, dothecall, NULL, savestack(L, L->top - 2), 0);
846 L->ci->callstatus &= ~CIST_FIN; /* not running a finalizer anymore */ 845 L->ci->callstatus &= ~CIST_FIN; /* not running a finalizer anymore */
847 L->allowhook = oldah; /* restore hooks */ 846 L->allowhook = oldah; /* restore hooks */
848 g->gcrunning = running; /* restore state */ 847 g->gcrunning = running; /* restore state */
849 if (status != LUA_OK) { /* error while running __gc? */ 848 if (unlikely(status != LUA_OK)) { /* error while running __gc? */
850 const char *msg = (ttisstring(s2v(L->top - 1))) 849 const char *msg = (ttisstring(s2v(L->top - 1)))
851 ? svalue(s2v(L->top - 1)) 850 ? svalue(s2v(L->top - 1))
852 : "error object is not a string"; 851 : "error object is not a string";
853 luaE_warning(L, "error in __gc metamethod (", 1); 852 luaE_warning(L, "error in __gc metamethod (", 1);
854 luaE_warning(L, msg, 1); 853 luaE_warning(L, msg, 1);
855 luaE_warning(L, ")", 0); 854 luaE_warning(L, ")", 0);
855 L->top--; /* pops error object */
856 } 856 }
857 } 857 }
858} 858}