From eb96593d0f1bb60fe6e955daa1a1b91ef65c69bd Mon Sep 17 00:00:00 2001 From: Daniel-Constantin Mierla Date: Mon, 9 Jul 2018 15:25:43 +0200 Subject: [PATCH] app_lua: restore top index to lua stack after executing a function - could be related to GH #1577 --- src/modules/app_lua/app_lua_api.c | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/src/modules/app_lua/app_lua_api.c b/src/modules/app_lua/app_lua_api.c index 7f0fd1fbc0d..97d141cd223 100644 --- a/src/modules/app_lua/app_lua_api.c +++ b/src/modules/app_lua/app_lua_api.c @@ -646,6 +646,7 @@ int app_lua_run_ex(sip_msg_t *msg, char *func, char *p1, char *p2, int ret; str txt; sip_msg_t *bmsg; + int ltop; if(_sr_L_env.LL==NULL) { @@ -663,7 +664,8 @@ int app_lua_run_ex(sip_msg_t *msg, char *func, char *p1, char *p2, } else LM_DBG("reload deactivated\n"); LM_DBG("executing Lua function: [[%s]]\n", func); - LM_DBG("lua top index is: %d\n", lua_gettop(_sr_L_env.LL)); + ltop = lua_gettop(_sr_L_env.LL); + LM_DBG("lua top index is: %d\n", ltop); lua_getglobal(_sr_L_env.LL, func); if(!lua_isfunction(_sr_L_env.LL, -1)) { @@ -674,8 +676,12 @@ int app_lua_run_ex(sip_msg_t *msg, char *func, char *p1, char *p2, lua_typename(_sr_L_env.LL,lua_type(_sr_L_env.LL, -1))); txt.s = (char*)lua_tostring(_sr_L_env.LL, -1); LM_ERR("error from Lua: %s\n", (txt.s)?txt.s:"unknown"); + /* restores the original stack size */ + lua_settop(_sr_L_env.LL, ltop); return -1; } else { + /* restores the original stack size */ + lua_settop(_sr_L_env.LL, ltop); return 1; } } @@ -721,13 +727,20 @@ int app_lua_run_ex(sip_msg_t *msg, char *func, char *p1, char *p2, } lua_pop(_sr_L_env.LL, 1); if(n==1) { + /* restores the original stack size */ + lua_settop(_sr_L_env.LL, ltop); return 1; } else { LM_ERR("error executing: %s (err: %d)\n", func, ret); + /* restores the original stack size */ + lua_settop(_sr_L_env.LL, ltop); return -1; } } + /* restores the original stack size */ + lua_settop(_sr_L_env.LL, ltop); + return 1; }