22 #include <RCF/test/Test.hpp>
24 #include <RCF/CustomAllocator.hpp>
26 #include <RCF/test/StackWalker.h>
29 #error CRT allocator hook only possible in debug builds.
32 bool gInstrumented =
false;
33 bool gExpectAllocations =
true;
34 std::size_t gnAllocations = 0;
36 static _CRT_ALLOC_HOOK pfnOldCrtAllocHook = NULL;
38 int crtAllocationHook(
44 const unsigned char *filename,
49 && (allocType == _HOOK_ALLOC || allocType == _HOOK_REALLOC)
50 && !gExpectAllocations)
55 gInstrumented =
false;
60 std::cout <<
"***************************************" << std::endl;
61 std::cout <<
"Unexpected memory allocation. Call stack:" << std::endl;
63 std::cout << StackTrace().toString() << std::endl;
65 std::cout <<
"***************************************" << std::endl;
67 RCF_CHECK(0 &&
"Unexpected memory allocation.");
70 if (allocType == _HOOK_ALLOC || allocType == _HOOK_REALLOC)
75 return pfnOldCrtAllocHook(
87 pfnOldCrtAllocHook = _CrtSetAllocHook(crtAllocationHook);
90 bool dummy = (setupHook(),
false);