From cca3053069e457c672e664f927a91c83d2bd18fe Mon Sep 17 00:00:00 2001 From: Daniel Gibson Date: Sun, 23 Dec 2012 05:14:48 +0100 Subject: [PATCH] Prevent segfault on shutdown This should also happen on Windows, I'm really surprised this hasn't been noticed there --- neo/idlib/containers/StrPool.h | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/neo/idlib/containers/StrPool.h b/neo/idlib/containers/StrPool.h index 5971a7e8..65ab7fa6 100644 --- a/neo/idlib/containers/StrPool.h +++ b/neo/idlib/containers/StrPool.h @@ -168,7 +168,23 @@ ID_INLINE void idStrPool::FreeString( const idPoolStr* poolStr ) { int i, hash; - assert( poolStr->numUsers >= 1 ); + /* + * DG: numUsers can actually be 0 when shutting down the game, because then + * first idCommonLocal::Quit() -> idCommonLocal::Shutdown() -> idLib::Shutdown() + * -> idDict::Shutdown() -> idDict::globalKeys.Clear() and idDict::globalVars.Clear() + * is called and then, from destructors, + * ~idSessionLocal() => destroy idDict titleStorageVars -> ~idDict() -> idDict::Clear() + * -> idDict::globalVars.FreeString() and idDict::globalKeys.FreeString() (this function) + * is called, leading here. + * So just return if poolStr->numUsers < 1, instead of segfaulting/asserting below + * when i == -1 because nothing was found here. As there is no nice way to find out if + * we're shutting down (at this point) just get rid of the following assertion: + * assert( poolStr->numUsers >= 1 ); + */ + if( poolStr->numUsers < 1 ) + return; + // DG end + assert( poolStr->pool == this ); poolStr->numUsers--;