From 2a15cf2b1f0fb02d9a34c2d5f81bf3a402cd244a Mon Sep 17 00:00:00 2001 From: Benny Prijono Date: Thu, 23 Nov 2006 07:31:27 +0000 Subject: Fixed crash in IoCompletionPort during unregistration. Also remove WSACleanup() from pj_shutdown() since it may not be a good idea (and for one thing it crashes with Invalid Handle exception) git-svn-id: http://svn.pjsip.org/repos/pjproject/trunk@821 74dad513-b988-da41-8d7b-12977e46ad98 --- pjlib/src/pj/ioqueue_winnt.c | 17 ++++++++++------- pjlib/src/pj/os_core_win32.c | 2 +- 2 files changed, 11 insertions(+), 8 deletions(-) diff --git a/pjlib/src/pj/ioqueue_winnt.c b/pjlib/src/pj/ioqueue_winnt.c index 71977cbd..ae6bb70e 100644 --- a/pjlib/src/pj/ioqueue_winnt.c +++ b/pjlib/src/pj/ioqueue_winnt.c @@ -687,6 +687,11 @@ PJ_DEF(pj_status_t) pj_ioqueue_unregister( pj_ioqueue_key_t *key ) pj_lock_release(ioqueue->lock); } #endif + +#if PJ_IOQUEUE_HAS_SAFE_UNREG + /* Mark key as closing before closing handle. */ + key->closing = 1; +#endif /* Close handle (the only way to disassociate handle from IOCP). * We also need to close handle to make sure that no further events @@ -701,12 +706,6 @@ PJ_DEF(pj_status_t) pj_ioqueue_unregister( pj_ioqueue_key_t *key ) key->cb.on_write_complete = NULL; #if PJ_IOQUEUE_HAS_SAFE_UNREG - /* Mark key as closing. */ - key->closing = 1; - - /* Decrement reference counter. */ - decrement_counter(key); - /* Even after handle is closed, I suspect that IOCP may still try to * do something with the handle, causing memory corruption when pool * debugging is enabled. @@ -714,7 +713,11 @@ PJ_DEF(pj_status_t) pj_ioqueue_unregister( pj_ioqueue_key_t *key ) * Forcing context switch seems to have fixed that, but this is quite * an ugly solution.. */ - pj_thread_sleep(0); + while (pj_atomic_get(key->ref_count) != 1) + pj_thread_sleep(0); + + /* Decrement reference counter to destroy the key. */ + decrement_counter(key); #endif return PJ_SUCCESS; diff --git a/pjlib/src/pj/os_core_win32.c b/pjlib/src/pj/os_core_win32.c index ea2c8d94..23e2cde1 100644 --- a/pjlib/src/pj/os_core_win32.c +++ b/pjlib/src/pj/os_core_win32.c @@ -219,7 +219,7 @@ PJ_DEF(void) pj_shutdown() } /* Shutdown Winsock */ - WSACleanup(); + //WSACleanup(); } -- cgit v1.2.3