diff --git a/apache2/msc_lua.c b/apache2/msc_lua.c index 8ba2ecc0..494727db 100644 --- a/apache2/msc_lua.c +++ b/apache2/msc_lua.c @@ -108,7 +108,9 @@ char *lua_compile(msc_script **script, const char *filename, apr_pool_t *pool) { (*script) = apr_pcalloc(pool, sizeof(msc_script)); (*script)->name = filename; (*script)->parts = dump.parts; - (*script)->Lstate = L; + + /* Destroy state. */ + lua_close(L); return NULL; } @@ -390,8 +392,8 @@ static const struct luaL_Reg mylib[] = { */ int lua_execute(msc_script *script, char *param, modsec_rec *msr, msre_rule *rule, char **error_msg) { apr_time_t time_before; - lua_State *L = script->Lstate; - int rc, lvm; + lua_State *L = NULL; + int rc; if (error_msg == NULL) return -1; *error_msg = NULL; @@ -402,16 +404,10 @@ int lua_execute(msc_script *script, char *param, modsec_rec *msr, msre_rule *rul time_before = apr_time_now(); - if (L == NULL) { - /* Create new state. */ - L = lua_open(); - luaL_openlibs(L); - lvm = 1; - if (L == NULL) { - *error_msg = apr_psprintf(msr->mp, "Lua: Failed to create Lua state"); - return -1; - } - } + /* Create new state. */ + L = lua_open(); + + luaL_openlibs(L); /* Associate msr with the state. */ lua_pushlightuserdata(L, (void *)msr); @@ -454,12 +450,9 @@ int lua_execute(msc_script *script, char *param, modsec_rec *msr, msre_rule *rul *error_msg = apr_pstrdup(msr->mp, *error_msg); } - lua_pop(L, 1); - /* Destroy state. */ - if(lvm) { - lua_close(L); - } + lua_pop(L, 1); + lua_close(L); /* Returns status code to caller. */ if (msr->txcfg->debuglog_level >= 8) { diff --git a/apache2/msc_lua.h b/apache2/msc_lua.h index af5d0328..1f8e50ee 100644 --- a/apache2/msc_lua.h +++ b/apache2/msc_lua.h @@ -31,7 +31,6 @@ typedef struct msc_script_part msc_script_part; struct msc_script { const char *name; apr_array_header_t *parts; - lua_State *Lstate; }; struct msc_script_part {