Delegate memory leak detection to CRT

_CrtDumpMemoryLeaks() direct call misreports heap allocations owned by
globally initialized objects.

Using _CRTDBG_LEAK_CHECK_DF delays the memory leak check until after
globally initialized objects are destroyed.

Signed-off-by: Simon Rozman <simon@rozman.si>
This commit is contained in:
2020-06-29 15:38:24 +02:00
parent 682dc048e9
commit 78478a203f
6 changed files with 21 additions and 28 deletions

View File

@@ -57,10 +57,10 @@ BOOL WINAPI DllMain(_In_ HINSTANCE hinstDLL, _In_ DWORD fdwReason, _In_ LPVOID l
if (fdwReason == DLL_PROCESS_ATTACH) {
#ifdef _DEBUG
//Sleep(10000);
_CrtSetDbgFlag(_crtDbgFlag | _CRTDBG_ALLOC_MEM_DF | _CRTDBG_CHECK_ALWAYS_DF | _CRTDBG_CHECK_CRT_DF | _CRTDBG_LEAK_CHECK_DF);
#endif
g_hInstance = hinstDLL;
} else if (fdwReason == DLL_PROCESS_DETACH)
assert(!_CrtDumpMemoryLeaks());
}
return TRUE;
}