Skip to content

Commit d74fc7c

Browse files
committed
[lua] fix stack cleanup in li_config_lua_load error handling
Change-Id: I12ccfe77d5a2af1016c844935c144fa6eb73335a
1 parent 8d050b7 commit d74fc7c

File tree

1 file changed

+11
-16
lines changed

1 file changed

+11
-16
lines changed

src/main/config_lua.c

Lines changed: 11 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -155,6 +155,7 @@ gboolean li_config_lua_load(liLuaState *LL, liServer *srv, liWorker *wrk, const
155155
int errfunc;
156156
int lua_stack_top;
157157
lua_State *L = LL->L;
158+
gboolean result;
158159

159160
*pact = NULL;
160161

@@ -183,27 +184,21 @@ gboolean li_config_lua_load(liLuaState *LL, liServer *srv, liWorker *wrk, const
183184
/* 2. args */
184185
li_lua_push_value(L, args); /* +1 */
185186

186-
errfunc = li_lua_push_traceback(L, 2); /* +1, but before args */
187+
errfunc = li_lua_push_traceback(L, 2); /* +1, but before func and 2 args */
187188
if (lua_pcall(L, 2, 0, errfunc)) { /* -3 (func + args), 0 results (but 1 error) */
188189
_ERROR(srv, wrk, NULL, "lua_pcall(): %s", lua_tostring(L, -1));
189190

190-
/* cleanup stack */
191-
if (lua_stack_top > lua_gettop(L)) {
192-
lua_pop(L, lua_gettop(L) - lua_stack_top);
193-
}
194-
195-
li_lua_environment_restore(LL); /* -1 */
196-
li_lua_environment_restore_globals(L); /* -1 */
191+
lua_pop(L, 1); /* -1 error */
197192

198-
li_lua_unlock(LL);
193+
result = FALSE;
194+
} else {
195+
lua_getglobal(L, "actions"); /* +1 */
196+
*pact = li_lua_get_action_ref(L, -1);
197+
lua_pop(L, 1); /* -1 */
199198

200-
return FALSE;
199+
result = TRUE;
201200
}
202-
lua_remove(L, errfunc);
203-
204-
lua_getglobal(L, "actions");
205-
*pact = li_lua_get_action_ref(L, -1);
206-
lua_pop(L, 1);
201+
lua_remove(L, errfunc); /* -1 */
207202

208203
LI_FORCE_ASSERT(lua_gettop(L) == lua_stack_top);
209204

@@ -214,5 +209,5 @@ gboolean li_config_lua_load(liLuaState *LL, liServer *srv, liWorker *wrk, const
214209

215210
li_lua_unlock(LL);
216211

217-
return TRUE;
212+
return result;
218213
}

0 commit comments

Comments
 (0)