Module: kamailio Branch: master Commit: eb96593d0f1bb60fe6e955daa1a1b91ef65c69bd URL: https://github.com/kamailio/kamailio/commit/eb96593d0f1bb60fe6e955daa1a1b91e...
Author: Daniel-Constantin Mierla miconda@gmail.com Committer: Daniel-Constantin Mierla miconda@gmail.com Date: 2018-07-09T15:25:43+02:00
app_lua: restore top index to lua stack after executing a function
- could be related to GH #1577
---
Modified: src/modules/app_lua/app_lua_api.c
---
Diff: https://github.com/kamailio/kamailio/commit/eb96593d0f1bb60fe6e955daa1a1b91e... Patch: https://github.com/kamailio/kamailio/commit/eb96593d0f1bb60fe6e955daa1a1b91e...
---
diff --git a/src/modules/app_lua/app_lua_api.c b/src/modules/app_lua/app_lua_api.c index 7f0fd1fbc0..97d141cd22 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; }