From f73eccfc8e589e6cc670c488b78715ee40b6985d Mon Sep 17 00:00:00 2001 From: William Ahern Date: Fri, 24 Jul 2015 20:14:06 -0700 Subject: Don't recreate an exdata state singleton object when one already exists, otherwise we wrongly invalidate any data already installed. Because ex_newstate is invoked from every submodule, this can easily happen if code loads one submodule, attaches some data to a new OpenSSL object, then loads some other submodule for the first time. --- src/openssl.c | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/src/openssl.c b/src/openssl.c index 7b2ce89..8977234 100644 --- a/src/openssl.c +++ b/src/openssl.c @@ -1185,6 +1185,15 @@ static void ex_newstate(lua_State *L) { struct ex_state *state; struct lua_State *thr; + lua_pushlightuserdata(L, (void *)&ex__gc); + lua_gettable(L, LUA_REGISTRYINDEX); + + if (!lua_isnil(L, -1)) { + lua_pop(L, 1); + + return; + } + state = prepudata(L, sizeof *state, NULL, &ex__gc); LIST_INIT(&state->data); -- cgit v1.2.3-59-g8ed1b