We do such checks by using the platform specific malloc hook facilities, every allocation triggered by new
or malloc
can be found this way. But it’s not portable. On macOS, you can inject your own malloc handler to the malloc zone returned by malloc_default_zone
, on Windows there is _CrtSetAllocHook.
2 Likes