From 638337384b3800f25165a80196d871ffbceb95e2 Mon Sep 17 00:00:00 2001 From: ehouse Date: Fri, 18 Dec 2009 04:24:55 +0000 Subject: [PATCH] set flag on exit and don't allocate anything or try to send via network; clear globals var after freeing it. --- xwords4/wince/cemain.c | 63 ++++++++++++++++++++++------------------ xwords4/wince/cemain.h | 1 + xwords4/wince/ceresstr.c | 8 +++++ 3 files changed, 43 insertions(+), 29 deletions(-) diff --git a/xwords4/wince/cemain.c b/xwords4/wince/cemain.c index 9918f24b1..5f821e0e2 100755 --- a/xwords4/wince/cemain.c +++ b/xwords4/wince/cemain.c @@ -2052,6 +2052,7 @@ ceSaveCurGame( CEAppGlobals* globals, XP_Bool autoSave ) static void ceSaveAndExit( CEAppGlobals* globals ) { + globals->exiting = XP_TRUE; (void)ceSaveCurGame( globals, XP_TRUE ); ceSavePrefs( globals ); DestroyWindow(globals->hWnd); @@ -2406,6 +2407,7 @@ WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam) } else { /* XP_LOGF( "%s: event=%s (%d)", __func__, messageToStr(message), message ); */ globals = (CEAppGlobals*)GetWindowLongPtr( hWnd, GWL_USERDATA ); + XP_ASSERT( !!globals ); switch (message) { @@ -2738,6 +2740,8 @@ WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam) #endif PostQuitMessage(0); freeGlobals( globals ); + globals = NULL; + SetWindowLongPtr( hWnd, GWL_USERDATA, 0L ); break; case XWWM_TIME_RQST: @@ -3148,42 +3152,45 @@ ce_send_proc( const XP_U8* buf, XP_U16 len, const CommsAddrRec* addrp, { XP_S16 nSent = -1; CEAppGlobals* globals = (CEAppGlobals*)closure; - CommsAddrRec addr; LOG_FUNC(); + if ( !globals->exiting ) { + CommsAddrRec addr; - XP_ASSERT( !!globals->game.comms ); + XP_ASSERT( !!globals->game.comms ); - if ( !addrp ) { - comms_getAddr( globals->game.comms, &addr ); - addrp = &addr; - } - - XP_ASSERT( !!addrp ); /* firing */ - switch( addrp->conType ) { -#if defined XWFEATURE_RELAY || defined XWFEATURE_BLUETOOTH - case COMMS_CONN_IP_DIRECT: - break; - case COMMS_CONN_RELAY: - if ( !globals->socketWrap ) { - globals->socketWrap = ce_sockwrap_new( MPPARM(globals->mpool) - globals->hWnd, - got_data_proc, - sock_state_change, globals ); + if ( !addrp ) { + comms_getAddr( globals->game.comms, &addr ); + addrp = &addr; } - nSent = ce_sockwrap_send( globals->socketWrap, buf, len, addrp ); - break; + XP_ASSERT( !!addrp ); /* firing */ + switch( addrp->conType ) { +#if defined XWFEATURE_RELAY || defined XWFEATURE_BLUETOOTH + case COMMS_CONN_IP_DIRECT: + break; + case COMMS_CONN_RELAY: + if ( !globals->exiting ) { + if ( !globals->socketWrap ) { + globals->socketWrap = ce_sockwrap_new( MPPARM(globals->mpool) + globals->hWnd, + got_data_proc, + sock_state_change, globals ); + } + + nSent = ce_sockwrap_send( globals->socketWrap, buf, len, addrp ); + break; #endif #ifdef XWFEATURE_SMS - case COMMS_CONN_SMS: - nSent = ce_sms_send( globals, buf, len, addrp ); - break; + case COMMS_CONN_SMS: + nSent = ce_sms_send( globals, buf, len, addrp ); + break; #endif - default: - XP_LOGF( "unexpected conType %d", addrp->conType ); - XP_ASSERT( 0 ); + default: + XP_LOGF( "unexpected conType %d", addrp->conType ); + XP_ASSERT( 0 ); + } + } } - return nSent; } /* ce_send_proc */ @@ -3752,8 +3759,6 @@ ce_util_addrChange( XW_UtilCtxt* uc, globals->socketWrap = NULL; } } - - XP_LOGF( "ce_util_addrChange called; DO SOMETHING." ); } /* ce_util_addrChange */ #endif diff --git a/xwords4/wince/cemain.h b/xwords4/wince/cemain.h index 8506255ac..57fa3be68 100755 --- a/xwords4/wince/cemain.h +++ b/xwords4/wince/cemain.h @@ -172,6 +172,7 @@ typedef struct _CEAppGlobals { XP_Bool penDown; XP_Bool hintPending; XP_Bool doGlobalPrefs; + XP_Bool exiting; /* are we in the process of shutting down? */ #ifdef XWFEATURE_RELAY CommsRelayState relayState; diff --git a/xwords4/wince/ceresstr.c b/xwords4/wince/ceresstr.c index 2b3ef382c..44fb3acf3 100644 --- a/xwords4/wince/ceresstr.c +++ b/xwords4/wince/ceresstr.c @@ -58,6 +58,9 @@ typedef struct _ResStrEntry { typedef struct _ResStrStorage { ResStrEntry* entries[CE_LAST_RES_ID - CE_FIRST_RES_ID + 1]; +#ifdef DEBUG + XP_U16 nUsed; +#endif } ResStrStorage; static const ResStrEntry* @@ -72,6 +75,7 @@ getEntry( CEAppGlobals* globals, XP_U16 resID, XP_Bool isWide ) XP_ASSERT( index < VSIZE(storage->entries) ); if ( !storage ) { + XP_ASSERT( !globals->exiting ); storage = XP_MALLOC( globals->mpool, sizeof( *storage ) ); XP_MEMSET( storage, 0, sizeof(*storage) ); globals->resStrStorage = storage; @@ -99,6 +103,9 @@ getEntry( CEAppGlobals* globals, XP_U16 resID, XP_Bool isWide ) } storage->entries[index] = entry; +#ifdef DEBUG + ++storage->nUsed; +#endif } return entry; @@ -165,6 +172,7 @@ ceFreeResStrings( CEAppGlobals* globals ) } } + XP_ASSERT( nUsed == storage->nUsed ); XP_FREE( globals->mpool, storage ); globals->resStrStorage = NULL; }