I've been trying debugging memory leaks for quite a bit of time now. My main problem is not being able to use proper tools like Valgrind and the like, so I settled for plain GDB + strace.
My program is a loop. On each iteration, it creates some objects, then calls their destructors. As it's explained here, after the first allocation at the first iteration of the loop, the program shouldn't ask for more memory, as it's always allocating the same objects and thus should always reuse the same space. Yet my program calls brk()
every 15 iterations, and the argument passed to brk
increases each time by 4.096 (like, 1st time: brk(0xb7887000) = 0xb7887000
, 2nd time: brk(0xb7888000) = 0xb7888000
, 3rd time: brk(0xb7889000) = 0xb7889000
, and so on).
Then I've tried hooking GDB to my program, let the program run for a few iterations, and set a breakpoint on brk with (gdb) break brk
.
It says it set a breakpoint on an address, but even if I let my program run for more than 15 iterations, the breakpoint is never "called" (?).
Why is that happening? How can I understand what's going on?