There seems to be a big problem of perception as to what a "possible leak" means.
Firstly, a leak is when memory is allocated but not deallocated. A false positive would be if Memcheck reports a leak when there isn't one. That could happen if you provide a replacement for malloc
but then use a non-standard name (say dealloc
) for your deallocation function rather than free
.
Secondly, there is the categorization of the leak. For each leak that Memcheck finds it will scan through memory and registers trying to find pointers to that memory block.
- If it finds no pointers that is a definite leak
- If it finds pointers in memory that is no longer accessible (deallocated) then that is an indirect leak
- If it finds pointers to the start of the memory block then that is reachable.
- If it finds pointers to somewhere inside the block other than the start then that's a possible leak. This could just be random junk that happens to be the same as the pointer. And it could be something like a redzone, size:data or the base-to-derived pointer in cmaster's example. It's difficult for Memcheck to tell whether it is accidental or not (there are a few heuristics). Since it can't tell it marks these as potential leaks.