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

This commit is contained in:
Aaron Kunze 2014-03-24 13:38:57 -07:00
parent 5600bc54f4
commit 629ddf0bf8
2 changed files with 11 additions and 5 deletions

View File

@ -1581,7 +1581,7 @@ void finish()
#define IMPLEMENT_REFCOUNTABLE() \
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
/////////////////////////////////////////// Platform /////////////////////////////////////////////

View File

@ -918,16 +918,22 @@ public:
#pragma warning(disable:4447) // Disable warning 'main' signature found without threading model
#endif
BOOL WINAPI DllMain(HINSTANCE, DWORD fdwReason, LPVOID);
extern "C"
BOOL WINAPI DllMain(HINSTANCE, DWORD fdwReason, LPVOID lpReserved)
{
if (fdwReason == DLL_THREAD_DETACH || fdwReason == DLL_PROCESS_DETACH)
{
if (lpReserved != NULL) // called after ExitProcess() call
{
cv::__termination = true;
cv::deleteThreadAllocData();
cv::deleteThreadData();
}
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::deleteThreadData();
}
}
return TRUE;
}