请看代码:(VS2005) //free : int _tmain(int argc, _TCHAR* argv[]) { int *p=NULL; p= (int *)malloc(sizeof(int)); free(p);//单步跟进 } //来到这里。 extern "C" _CRTIMP void __cdecl free( void * pUserData ) { _free_dbg(pUserData, _NORMAL_BLOCK);//单步跟进 } //来到这里 extern "C" _CRTIMP void __cdecl _free_dbg( void * pUserData, int nBlockUse ) { /* lock the heap */ _mlock(_HEAP_LOCK); __try { /* allocate the block */ _free_dbg_nolock(pUserData, nBlockUse);//单步跟进 } __finally { /* unlock the heap */ _munlock(_HEAP_LOCK); } } //来到这里 extern "C" void __cdecl _free_dbg_nolock( void * pUserData, int nBlockUse ) {//这里检查了指针所指的堆空间,如果正确则调用void __cdecl _free_base (void * pBlock)释放堆空间 _CrtMemBlockHeader * pHead; RTCCALLBACK(_RTC_Free_hook, (pUserData, 0)); /* verify heap before freeing */ if (check_frequency > 0) if (check_counter == (check_frequency - 1)) { _ASSERTE(_CrtCheckMemory()); check_counter = 0; } else check_counter++; if (pUserData == NULL) return; /* check if the heap was not allocated by _aligned routines */ if ( nBlockUse == _NORMAL_BLOCK) { if ( CheckBytes((unsigned char*)((uintptr_t)pUserData & ~(sizeof(uintptr_t) -1)) -nAlignGapSize,