I have an issue of finding out of who is allocating memory to the variable in an extremely large code base in visual studio. For Example: I have a structure
struct test
{
char *point;
}*obj;
obj = malloc(sizeof(struct test));
obj->point = malloc(100);
Variable obj
is passed around the entire code, and at some place obj->point is reallocated without freeing the old memory. However, this happens at so many locations that it is impossible to keep track of which one is actually doing it. Is there anyway in visual studio, to keep a conditional breakpoint, where I will get notified if the old memory is replaced with a new one
If there's a specific object you want to track than you can set up a data breakpoint on
&obj->point
. Whenever this pointer changes the debugger will stop the application.In Visual Studio, place a regular breakpoint when your obj is created. Go to the breakpoints window and select "New->New Data Breakpoint". For the address enter
&obj->point
and select the data size (4/8 for 32/64 bit).