fix(lua): workaround memory leak problem with __cxa_thread_atexit code generated by g++

Signed-off-by: Leonardo de Moura <leonardo@microsoft.com>
This commit is contained in:
Leonardo de Moura 2013-11-18 06:40:32 -08:00
parent 7976937e4c
commit 2ccd5cc559

View file

@ -105,8 +105,9 @@ void pcall(lua_State * L, int nargs, int nresults, int errorfun) {
throw lua_exception(lua_tostring(L, -1)); throw lua_exception(lua_tostring(L, -1));
} }
static thread_local std::string g_error_msg;
int safe_function_wrapper(lua_State * L, lua_CFunction f){ int safe_function_wrapper(lua_State * L, lua_CFunction f){
static thread_local std::string _error_msg;
char const * error_msg; char const * error_msg;
try { try {
return f(L); return f(L);
@ -114,19 +115,19 @@ int safe_function_wrapper(lua_State * L, lua_CFunction f){
std::ostringstream out; std::ostringstream out;
options o = get_global_options(L); options o = get_global_options(L);
out << mk_pair(e.pp(get_global_formatter(L), o), o); out << mk_pair(e.pp(get_global_formatter(L), o), o);
_error_msg = out.str(); g_error_msg = out.str();
error_msg = _error_msg.c_str(); error_msg = g_error_msg.c_str();
} catch (elaborator_exception & e) { } catch (elaborator_exception & e) {
push_justification(L, e.get_justification()); push_justification(L, e.get_justification());
return lua_error(L); return lua_error(L);
} catch (exception & e) { } catch (exception & e) {
_error_msg = e.what(); g_error_msg = e.what();
error_msg = _error_msg.c_str(); error_msg = g_error_msg.c_str();
} catch (std::bad_alloc &) { } catch (std::bad_alloc &) {
error_msg = "out of memory"; error_msg = "out of memory";
} catch (std::exception & e) { } catch (std::exception & e) {
_error_msg = e.what(); g_error_msg = e.what();
error_msg = _error_msg.c_str(); error_msg = g_error_msg.c_str();
} catch(...) { } catch(...) {
throw; throw;
} }