Resolves bug #3450 (Improperly cleaning up resources in DllMain)

pull/2594/head
Aaron Kunze 11 years ago
parent 5600bc54f4
commit 629ddf0bf8
  1. 2
      modules/core/src/ocl.cpp
  2. 10
      modules/core/src/system.cpp

@ -1581,7 +1581,7 @@ void finish()
#define IMPLEMENT_REFCOUNTABLE() \ #define IMPLEMENT_REFCOUNTABLE() \
void addref() { CV_XADD(&refcount, 1); } \ void addref() { CV_XADD(&refcount, 1); } \
void release() { if( CV_XADD(&refcount, -1) == 1 ) delete this; } \ void release() { if( CV_XADD(&refcount, -1) == 1 && !cv::__termination) delete this; } \
int refcount int refcount
/////////////////////////////////////////// Platform ///////////////////////////////////////////// /////////////////////////////////////////// Platform /////////////////////////////////////////////

@ -918,17 +918,23 @@ public:
#pragma warning(disable:4447) // Disable warning 'main' signature found without threading model #pragma warning(disable:4447) // Disable warning 'main' signature found without threading model
#endif #endif
BOOL WINAPI DllMain(HINSTANCE, DWORD fdwReason, LPVOID); extern "C"
BOOL WINAPI DllMain(HINSTANCE, DWORD fdwReason, LPVOID lpReserved) BOOL WINAPI DllMain(HINSTANCE, DWORD fdwReason, LPVOID lpReserved)
{ {
if (fdwReason == DLL_THREAD_DETACH || fdwReason == DLL_PROCESS_DETACH) if (fdwReason == DLL_THREAD_DETACH || fdwReason == DLL_PROCESS_DETACH)
{ {
if (lpReserved != NULL) // called after ExitProcess() call if (lpReserved != NULL) // called after ExitProcess() call
{
cv::__termination = true; cv::__termination = true;
}
else
{
// Not allowed to free resources if lpReserved is non-null
// http://msdn.microsoft.com/en-us/library/windows/desktop/ms682583.aspx
cv::deleteThreadAllocData(); cv::deleteThreadAllocData();
cv::deleteThreadData(); cv::deleteThreadData();
} }
}
return TRUE; return TRUE;
} }
#endif #endif

Loading…
Cancel
Save