From c2a7a5c3478bcb334354f5049c4613504814c026 Mon Sep 17 00:00:00 2001 From: Andy2 Date: Tue, 18 Oct 2011 21:29:40 -0700 Subject: [PATCH] fix crash: don't destroy stream if for some reason it's null. Not sure how that happens, but it does. --- xwords4/common/server.c | 122 +++++++++++++++++++++------------------- 1 file changed, 64 insertions(+), 58 deletions(-) diff --git a/xwords4/common/server.c b/xwords4/common/server.c index 68f7c94d0..01c1529a4 100644 --- a/xwords4/common/server.c +++ b/xwords4/common/server.c @@ -865,8 +865,11 @@ showPrevScore( ServerCtxt* server ) util_informMove( util, stream, server->nv.prevWordsStream ); stream_destroy( stream ); - stream_destroy( server->nv.prevWordsStream ); - server->nv.prevWordsStream = NULL; + + if ( !!server->nv.prevWordsStream ) { + stream_destroy( server->nv.prevWordsStream ); + server->nv.prevWordsStream = NULL; + } } SETSTATE( server, server->nv.stateAfterShow ); } /* showPrevScore */ @@ -875,76 +878,79 @@ XP_Bool server_do( ServerCtxt* server ) { XP_Bool result = XP_TRUE; - XP_Bool moreToDo = XP_FALSE; if ( server->serverDoing ) { - return XP_FALSE; - } - server->serverDoing = XP_TRUE; + result = XP_FALSE; + } else { + XP_Bool moreToDo = XP_FALSE; + server->serverDoing = XP_TRUE; - switch( server->nv.gameState ) { - case XWSTATE_BEGIN: - if ( server->nv.pendingRegistrations == 0 ) { /* all players on device */ - assignTilesToAll( server ); + switch( server->nv.gameState ) { + case XWSTATE_BEGIN: + if ( server->nv.pendingRegistrations == 0 ) { /* all players on + device */ + assignTilesToAll( server ); + SETSTATE( server, XWSTATE_INTURN ); + setTurn( server, 0 ); + moreToDo = XP_TRUE; + } + break; + + case XWSTATE_NEEDSEND_BADWORD_INFO: + XP_ASSERT( server->vol.gi->serverRole == SERVER_ISSERVER ); + badWordMoveUndoAndTellUser( server, &server->illegalWordInfo ); +#ifndef XWFEATURE_STANDALONE_ONLY + sendBadWordMsgs( server ); +#endif + nextTurn( server, PICK_NEXT ); /* sets server->nv.gameState */ + //moreToDo = XP_TRUE; /* why? */ + break; + +#ifndef XWFEATURE_STANDALONE_ONLY + case XWSTATE_RECEIVED_ALL_REG: + server_sendInitialMessage( server ); + /* PENDING isn't INTURN_OFFDEVICE possible too? Or just + INTURN? */ SETSTATE( server, XWSTATE_INTURN ); setTurn( server, 0 ); moreToDo = XP_TRUE; - } - break; + break; - case XWSTATE_NEEDSEND_BADWORD_INFO: - XP_ASSERT( server->vol.gi->serverRole == SERVER_ISSERVER ); - badWordMoveUndoAndTellUser( server, &server->illegalWordInfo ); -#ifndef XWFEATURE_STANDALONE_ONLY - sendBadWordMsgs( server ); -#endif - nextTurn( server, PICK_NEXT ); /* sets server->nv.gameState */ - //moreToDo = XP_TRUE; /* why? */ - break; - -#ifndef XWFEATURE_STANDALONE_ONLY - case XWSTATE_RECEIVED_ALL_REG: - server_sendInitialMessage( server ); - /* PENDING isn't INTURN_OFFDEVICE possible too? Or just INTURN? */ - SETSTATE( server, XWSTATE_INTURN ); - setTurn( server, 0 ); - moreToDo = XP_TRUE; - break; - - case XWSTATE_MOVE_CONFIRM_MUSTSEND: - XP_ASSERT( server->vol.gi->serverRole == SERVER_ISSERVER ); - tellMoveWasLegal( server ); - nextTurn( server, PICK_NEXT ); - break; + case XWSTATE_MOVE_CONFIRM_MUSTSEND: + XP_ASSERT( server->vol.gi->serverRole == SERVER_ISSERVER ); + tellMoveWasLegal( server ); + nextTurn( server, PICK_NEXT ); + break; #endif /* XWFEATURE_STANDALONE_ONLY */ - case XWSTATE_NEEDSEND_ENDGAME: - endGameInternal( server, END_REASON_OUT_OF_TILES ); - break; + case XWSTATE_NEEDSEND_ENDGAME: + endGameInternal( server, END_REASON_OUT_OF_TILES ); + break; - case XWSTATE_NEED_SHOWSCORE: - showPrevScore( server ); - moreToDo = XP_TRUE; /* either process turn or end game... */ - break; - case XWSTATE_INTURN: - if ( robotMovePending( server ) && !ROBOTWAITING(server) ) { - result = makeRobotMove( server ); - /* if robot was interrupted, we need to schedule again */ - moreToDo = !result || - (robotMovePending( server ) && !POSTPONEROBOTMOVE(server)); + case XWSTATE_NEED_SHOWSCORE: + showPrevScore( server ); + moreToDo = XP_TRUE; /* either process turn or end game... */ + break; + case XWSTATE_INTURN: + if ( robotMovePending( server ) && !ROBOTWAITING(server) ) { + result = makeRobotMove( server ); + /* if robot was interrupted, we need to schedule again */ + moreToDo = !result || + (robotMovePending( server ) && !POSTPONEROBOTMOVE(server)); + } + break; + + default: + result = XP_FALSE; + break; + } + if ( moreToDo ) { + util_requestTime( server->vol.util ); } - break; - default: - result = XP_FALSE; - break; + server->serverDoing = XP_FALSE; } - if ( moreToDo ) { - util_requestTime( server->vol.util ); - } - - server->serverDoing = XP_FALSE; return result; } /* server_do */