I have a memory leak in my program. I have replaced all calls to malloc
(and new
) with calls to my own function, which tracks allocated things. At the end of the program, I compare the things allocated at the beginning, and the ones at the end, to get the list of everything that is "leaking".
The end goal is to take the list of "leaking" locations, and put them in an array. Every time something is allocated, it is checked against the list of "leaking" addresses, and if there is a match, it calls a special function which I can then set a breakpoint on (where I can then figure out which objects are leaking and deal with them appropriately).
The problem is, the first few parts of the address changes each time the program runs. For example, the first time, one "leaking" address would be 0x10c10
and the next time, it may be 0x20c10
. The last few digits are always the same, but the first few are not.
Is there a way I can compare only the last few digits? I was thinking using mod, but I wasn't able to come up with anything that worked. These are regular integers, not strings or anything.