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. 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. -- Michael Kjörling 🔗 https://michael.kjorling.se