From 2ccd5cc559e871fdaaaae20a197d39dcfd22ee3f Mon Sep 17 00:00:00 2001 From: Leonardo de Moura Date: Mon, 18 Nov 2013 06:40:32 -0800 Subject: [PATCH] fix(lua): workaround memory leak problem with __cxa_thread_atexit code generated by g++ Signed-off-by: Leonardo de Moura --- src/bindings/lua/util.cpp | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/src/bindings/lua/util.cpp b/src/bindings/lua/util.cpp index e68633b3b..3316f2c1d 100644 --- a/src/bindings/lua/util.cpp +++ b/src/bindings/lua/util.cpp @@ -105,8 +105,9 @@ void pcall(lua_State * L, int nargs, int nresults, int errorfun) { 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){ - static thread_local std::string _error_msg; char const * error_msg; try { return f(L); @@ -114,19 +115,19 @@ int safe_function_wrapper(lua_State * L, lua_CFunction f){ std::ostringstream out; options o = get_global_options(L); out << mk_pair(e.pp(get_global_formatter(L), o), o); - _error_msg = out.str(); - error_msg = _error_msg.c_str(); + g_error_msg = out.str(); + error_msg = g_error_msg.c_str(); } catch (elaborator_exception & e) { push_justification(L, e.get_justification()); return lua_error(L); } catch (exception & e) { - _error_msg = e.what(); - error_msg = _error_msg.c_str(); + g_error_msg = e.what(); + error_msg = g_error_msg.c_str(); } catch (std::bad_alloc &) { error_msg = "out of memory"; } catch (std::exception & e) { - _error_msg = e.what(); - error_msg = _error_msg.c_str(); + g_error_msg = e.what(); + error_msg = g_error_msg.c_str(); } catch(...) { throw; }