Merge pull request #1101 in FS/freeswitch from ~MOTEUS/freeswitch:mod_lua_leak to master

* commit '672b5d8309b57f4f6996bded4fa365b90a8516ac':
  FS-9821 [mod_lua] Fix. memory/resource leak in mod_lua
This commit is contained in:
Mike Jerris 2016-12-07 13:31:57 -06:00
commit a38b246a6e

View File

@ -237,9 +237,10 @@ static switch_xml_t lua_fetch(const char *section,
switch_xml_t xml = NULL; switch_xml_t xml = NULL;
char *mycmd = NULL; char *mycmd = NULL;
lua_State *L = NULL;
if (!zstr(globals.xml_handler)) { if (!zstr(globals.xml_handler)) {
lua_State *L = lua_init(); L = lua_init();
const char *str; const char *str;
int error; int error;
@ -285,14 +286,16 @@ static switch_xml_t lua_fetch(const char *section,
} }
} }
lua_uninit(L);
} }
end: end:
switch_safe_free(mycmd); switch_safe_free(mycmd);
if (L) {
lua_uninit(L);
}
return xml; return xml;
} }
@ -519,14 +522,13 @@ SWITCH_STANDARD_CHAT_APP(lua_chat_function)
SWITCH_STANDARD_API(lua_api_function) SWITCH_STANDARD_API(lua_api_function)
{ {
lua_State *L = lua_init();
char *mycmd; char *mycmd;
int error; int error;
if (zstr(cmd)) { if (zstr(cmd)) {
stream->write_function(stream, ""); stream->write_function(stream, "");
} else { } else {
lua_State *L = lua_init();
mycmd = strdup(cmd); mycmd = strdup(cmd);
switch_assert(mycmd); switch_assert(mycmd);