On 16/12/24 at 16:43, Michael Kjörling wrote:
On 16 Dec 2024 16:05 +0100, from martelli...@gmail.com (Franco Martelli):
Is there a memory leak? What it sounds strange to me is that Valgrind
reports: "total heap usage: 9 allocs, 8 frees, …" when for me the calls to
"malloc" should be 8, not 9.

Put in something to count the number of calls to malloc() and free()
respectively. Don't forget calls outside of loops.

I did it, I've put a "cnt" variable in body of the "for loop" in main() and it results in 8 calls.
There isn't calls to malloc() or free() outside loops. What do you mean?

This can be as simple as a `printf("+");` and `printf("-");`
respectively at each call site. Or put breakpoints at each (or at the
respective function entry point) and keep a manual count.

See how many times each is reached.

I don't know how to put breakpoints, I'm new to gdb :(

--
Franco Martelli

Reply via email to