From 95a70862be228243ba27113e62470eea84e51ce9 Mon Sep 17 00:00:00 2001 From: ehouse Date: Sun, 30 Aug 2009 15:18:40 +0000 Subject: [PATCH] Lock cref before calling method that assumes lock. --- xwords4/relay/crefmgr.cpp | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/xwords4/relay/crefmgr.cpp b/xwords4/relay/crefmgr.cpp index e8020cca6..80e473958 100644 --- a/xwords4/relay/crefmgr.cpp +++ b/xwords4/relay/crefmgr.cpp @@ -143,9 +143,17 @@ CRefMgr::FindOpenGameFor( const char* cookie, const char* connName, if ( 0 == strcmp( cref->Cookie(), cookie ) ) { if ( cref->NeverFullyConnected() ) { found = cref; - } else if ( cref->HasSocket(socket) ) { - logf( XW_LOGINFO, "%s: HasSocket case", __func__ ); - found = cref; + } else { + if ( cref->Lock() ) { + if ( cref->AcceptingReconnections( hid, cookie, + nPlayersH ) ) { + found = cref; + } else if ( cref->HasSocket_locked(socket) ) { + logf( XW_LOGINFO, "%s: HasSocket case", __func__); + found = cref; + } + cref->Unlock(); + } } } } @@ -399,7 +407,7 @@ CRefMgr::heartbeatProc( void* closure ) CookieRef* CRefMgr::AddNew( const char* cookie, const char* connName, CookieID id ) { - logf( XW_LOGINFO, "%s( cookie=%s, connName=%s, id=%d", __func__, + logf( XW_LOGINFO, "%s( cookie=%s, connName=%s, cid=%d)", __func__, cookie, connName, id ); CookieRef* ref = getFromFreeList();