From 12483d5ee3c68701cbdc853d91e8c2138241fbd4 Mon Sep 17 00:00:00 2001 From: Alexey Melnichuk Date: Wed, 7 Dec 2016 10:06:48 +0300 Subject: [PATCH] FS-9821 [mod_lua] Fix. memory/resource leak in mod_lua --- src/mod/languages/mod_lua/mod_lua.cpp | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/src/mod/languages/mod_lua/mod_lua.cpp b/src/mod/languages/mod_lua/mod_lua.cpp index 21855e3980..51c000abd0 100644 --- a/src/mod/languages/mod_lua/mod_lua.cpp +++ b/src/mod/languages/mod_lua/mod_lua.cpp @@ -237,9 +237,10 @@ static switch_xml_t lua_fetch(const char *section, switch_xml_t xml = NULL; char *mycmd = NULL; + lua_State *L = NULL; if (!zstr(globals.xml_handler)) { - lua_State *L = lua_init(); + L = lua_init(); const char *str; int error; @@ -285,14 +286,16 @@ static switch_xml_t lua_fetch(const char *section, } } - lua_uninit(L); - } end: switch_safe_free(mycmd); + if (L) { + lua_uninit(L); + } + return xml; } @@ -519,14 +522,13 @@ SWITCH_STANDARD_CHAT_APP(lua_chat_function) SWITCH_STANDARD_API(lua_api_function) { - lua_State *L = lua_init(); char *mycmd; int error; if (zstr(cmd)) { stream->write_function(stream, ""); } else { - + lua_State *L = lua_init(); mycmd = strdup(cmd); switch_assert(mycmd);