diff --git a/src/modules/app_lua/app_lua_api.c b/src/modules/app_lua/app_lua_api.c index 575ee4454b2..7ccd9808501 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; }