Index: ext/libicpf/src/dmutex.cpp =================================================================== diff -u -N -r4fc59c1f72a9114bcecc969eba73746488601e16 -re22bbfa3fcb240e338ee67450c4ed8ce57c5d476 --- ext/libicpf/src/dmutex.cpp (.../dmutex.cpp) (revision 4fc59c1f72a9114bcecc969eba73746488601e16) +++ ext/libicpf/src/dmutex.cpp (.../dmutex.cpp) (revision e22bbfa3fcb240e338ee67450c4ed8ce57c5d476) @@ -92,15 +92,15 @@ if (m_pContext) { #ifdef _WIN32 - uint_t uiThread=GetThreadId(GetCurrentThread()); + uint_t uiThread=GetCurrentThreadId(); uint_t uiTime=GetTickCount(); #else // TODO: linux version of thread id must be put here sometime in the future assert(false); uint_t uiThread=0; uint_t uiTime=time(NULL); #endif - sprintf(sz, "[%lu][%lu][%s] Lock attempt (current lock count: %lu) in (%s - %lu: %s)", uiTime, uiThread, m_pszName, m_ulLockCount, pszFile, ulLine, pszFunction); + _snprintf(sz, 512, "[%lu][%lu][%s] Lock attempt (current lock count: %lu) in (%s - %lu: %s)", uiTime, uiThread, m_pszName, m_ulLockCount, pszFile, ulLine, pszFunction); m_pContext->open(sz); m_pContext->close(); } @@ -113,15 +113,15 @@ if (m_pContext) { #ifdef _WIN32 - uint_t uiThread=GetThreadId(GetCurrentThread()); + uint_t uiThread=GetCurrentThreadId(); uint_t uiTime=GetTickCount(); #else // TODO: linux version of thread id must be put here sometime in the future assert(false); uint_t uiThread=0; uint_t uiTime=time(NULL); #endif - sprintf(sz, "[%lu][%lu][%s] LOCKED (current lock count: %lu) in (%s - %lu: %s)", uiTime, uiThread, m_pszName, m_ulLockCount, pszFile, ulLine, pszFunction); + _snprintf(sz, 512, "[%lu][%lu][%s] LOCKED (current lock count: %lu) in (%s - %lu: %s)", uiTime, uiThread, m_pszName, m_ulLockCount, pszFile, ulLine, pszFunction); m_pContext->open(sz); m_pContext->close(); } @@ -143,15 +143,15 @@ if (m_pContext) { #ifdef _WIN32 - uint_t uiThread=GetThreadId(GetCurrentThread()); + uint_t uiThread=GetCurrentThreadId(); uint_t uiTime=GetTickCount(); #else // TODO: linux version of thread id must be put here sometime in the future assert(false); uint_t uiThread=0; uint_t uiTime=time(NULL); #endif - sprintf(sz, "[%lu][%lu][%s] Unlock attempt (current lock count: %lu) in (%s - %lu: %s)", uiTime, uiThread, m_pszName, m_ulLockCount, pszFile, ulLine, pszFunction); + _snprintf(sz, 512, "[%lu][%lu][%s] Unlock attempt (current lock count: %lu) in (%s - %lu: %s)", uiTime, uiThread, m_pszName, m_ulLockCount, pszFile, ulLine, pszFunction); m_pContext->open(sz); m_pContext->close(); } @@ -160,19 +160,24 @@ m_ulLockCount--; ((mutex*)this)->unlock(); - // pre-lock notification + // post-unlock notification + // NOTE: code here is quite dangerous - and could CRASH the application; + // we have just unlocked the real mutex, so anyone has access to the object protected + // by this d_mutex. If the object being protected is removed - the internal members + // would be invalid. It especially have some meaning for the sprintf function + // probably because of the m_pszName member if (m_pContext) { #ifdef _WIN32 - uint_t uiThread=GetThreadId(GetCurrentThread()); + uint_t uiThread=GetCurrentThreadId(); uint_t uiTime=GetTickCount(); #else // TODO: linux version of thread id must be put here sometime in the future assert(false); uint_t uiThread=0; uint_t uiTime=time(NULL); #endif - sprintf(sz, "[%lu][%lu][%s] UNLOCKED (current lock count: %lu) in (%s - %lu: %s)", uiTime, uiThread, m_pszName, m_ulLockCount, pszFile, ulLine, pszFunction); + _snprintf(sz, 512, "[%lu][%lu][%s] UNLOCKED (current lock count: %lu) in (%s - %lu: %s)", uiTime, uiThread, m_pszName, m_ulLockCount, pszFile, ulLine, pszFunction); m_pContext->open(sz); m_pContext->close(); }