Some examples of the fact that the documentation has different libraries that have their own allocators and for which the returned memory is not a direct pointer returned by the main OS allocator (malloc / sbrk), but a pointer after the offset. Consider, for example, a allocator that received some additional memory and stored meta-information (maybe type information for a garbage collector ...). The distribution and release process will be similar to:
void* allocate( size_t size ) { metainfo_t *m = (metainfo_t*) malloc( size + sizeof(metainfo) ); m->data = some_value; return (void*)(m+1);
When valgrind keeps track of memory, it remembers the original pointer that was returned by malloc , and this pointer is not stored anywhere in the program. But this does not mean that the memory has leaked, it means that the pointer is not directly accessible in the program. In particular, memory still contains the returned pointer, and deallocate can be called to release it, but valgrind does not see the original returned pointer in the place (char*)memory - sizeof(metadata_t) anywhere in the program and warns.
David Rodríguez - dribeas
source share