From ef1a830d57b289d2e4f3e907c60a4d8212609629 Mon Sep 17 00:00:00 2001 From: Paul Kulchenko Date: Fri, 8 Apr 2022 21:25:15 -0700 Subject: [PATCH] Reset Lua stack to drop unused returned values Since some Lua code may return values that will be left on stack, they need to be removed to avoid growing the stack unnecessarily. --- tool/net/redbean.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/tool/net/redbean.c b/tool/net/redbean.c index abf20524b..cc736e2bc 100644 --- a/tool/net/redbean.c +++ b/tool/net/redbean.c @@ -176,6 +176,7 @@ STATIC_YOINK("zip_uri_support"); char *s = LuaFormatStack(L); \ WARNF("lua stack should be empty!\n%s", s); \ free(s); \ + lua_settop(L, 0); \ } \ } while (0) @@ -1065,9 +1066,9 @@ static bool LuaOnClientConnection(void) { dropit = lua_toboolean(L, -1); } else { LogLuaError("OnClientConnection", lua_tostring(L, -1)); - lua_pop(L, 1); // pop error dropit = false; } + lua_pop(L, 1); // pop result or error AssertLuaStackIsEmpty(L); return dropit; #else