From c57bc44324a767407d1eb9f95e3c7589700f042e Mon Sep 17 00:00:00 2001 From: Benoit Germain Date: Wed, 7 Nov 2018 08:19:46 +0100 Subject: Fix potential crash at application shutdown when deep userdata were created before Lanes is required --- CHANGES | 3 +++ src/lanes.c | 5 ++++- src/universe.c | 9 ++++++++- 3 files changed, 15 insertions(+), 2 deletions(-) diff --git a/CHANGES b/CHANGES index 440ade4..be0e7d9 100644 --- a/CHANGES +++ b/CHANGES @@ -1,5 +1,8 @@ CHANGES: +CHANGE 131: BGe 7-Nov-18 + * Fix potential crash at application shutdown when deep userdata were created before Lanes is required + CHANGE 130: BGe 2-Nov-18 * always duplicate the config structure in new lanes even when no libraries are initialized by the generator (fixes an internal error trying to call on_state_create in a lane without any libs loaded) diff --git a/src/lanes.c b/src/lanes.c index 7b1a707..d4b4c73 100644 --- a/src/lanes.c +++ b/src/lanes.c @@ -1756,7 +1756,10 @@ static int selfdestruct_gc( lua_State* L) // Locks for 'tools.c' inc/dec counters MUTEX_FREE( &U->deep_lock); MUTEX_FREE( &U->mtid_lock); - + // universe is no longer available (nor necessary) + // we need to do this in case some deep userdata objects were created before Lanes was initialized, + // as potentially they will be garbage collected after Lanes at application shutdown + universe_store( L, NULL); return 0; } diff --git a/src/universe.c b/src/universe.c index 00de1f3..4689a09 100644 --- a/src/universe.c +++ b/src/universe.c @@ -56,7 +56,14 @@ void universe_store( lua_State* L, Universe* U) { STACK_CHECK( L); push_unique_key( L, UNIVERSE_REGKEY); - lua_pushlightuserdata( L, U); + if( NULL != U) + { + lua_pushlightuserdata( L, U); + } + else + { + lua_pushnil( L); + } lua_rawset( L, LUA_REGISTRYINDEX); STACK_END( L, 0); } -- cgit v1.2.3-55-g6feb