// crt_setbrkal.c
// compile with: -D_DEBUG /MTd -Od -Zi -W3 /c /link -verbose:lib -debug
/*
* In this program, a call is made to the _CrtSetBreakAlloc routine
* to verify that the debugger halts program execution when it reaches
* a specified allocation number.
*/
#include <malloc.h>
#include <crtdbg.h>
int main( )
{
long allocReqNum;
char *my_pointer;
/*
* Allocate "my_pointer" for the first
* time and ensure that it gets allocated correctly
*/
my_pointer = malloc(10);
_CrtIsMemoryBlock(my_pointer, 10, &allocReqNum, NULL, NULL);
/*
* Set a breakpoint on the allocation request
* number for "my_pointer"
*/
_CrtSetBreakAlloc(allocReqNum+2);
_crtBreakAlloc = allocReqNum+2;
/*
* Alternate freeing and reallocating "my_pointer"
* to verify that the debugger halts program execution
* when it reaches the allocation request
*/
free(my_pointer);
my_pointer = malloc(10);
free(my_pointer);
my_pointer = malloc(10);
free(my_pointer);
}