Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // Call first to register hook
- _CrtSetAllocHook(&zero_fill);
- int zero_fill(int nAllocType,
- void* pvData,
- size_t nSize,
- int nBlockUse,
- long lRequest,
- const unsigned char *szFileName,
- int nLine )
- /// Very Importaint !!
- /// infinite recursion if this is removed !!
- /// _CRT_BLOCK must not do any thing but return TRUE
- /// even calling printf in the _CRT_BLOCK will cause
- /// infinite recursion
- if ( nBlockUse == _CRT_BLOCK )
- return( TRUE );
- switch(nAllocType)
- {
- case _HOOK_ALLOC:
- case _HOOK_REALLOC:
- // zero initialize the allocated space.
- memset(pvData,0,nSize);
- break;
- case _HOOK_FREE:
- break;
- }
- return TRUE;
- char * p = new char[16]; // 16 bytes of random trash
- strcpy(p, "StackOverflow"); // 13 characters, a '