>> I'm using valgrind 3.8.0.SVN from MacPorts on Mac OS X 10.7.4. >> valgrind is showing a memory leak of 18 bytes when I try to allocate >> an empty array using posix_memalign. The leak warning is attached. >> >> The posix_memalign call is >> >> void* data; >> const size_t alignment = max(sizeof(T),sizeof(void*)); >> if (posix_memalign(&data,alignment,sizeof(T)*size)) >> throw bad_alloc(); >> >> where sizeof(T)==64 and size==0. I've confirmed that I call free on >> the same pointer. If I replace the code with >> >> void* data = malloc(sizeof(T)*size); >> >> the leak warning goes away. Any idea what could be going wrong?
There is a dispute about the meaning of memory allocation when the requested size is 0. The recipient must not access any memory there; after all, the requested size is zero. Also, NULL strings occur *everywhere*, so *any* address ought to be satisfactory for a zero-length block. However, some users were in the habit of using malloc(0) as an implementation of the LISP (gensym). The standard grudgingly accommodated those users. That was a mistake. The result is that most implementations allocate 1 byte when you ask for zero. -- ------------------------------------------------------------------------------ Live Security Virtual Conference Exclusive live event will cover all the ways today's security and threat landscape has changed and how IT managers can respond. Discussions will include endpoint security, mobile security and the latest in malware threats. http://www.accelacomm.com/jaw/sfrnl04242012/114/50122263/ _______________________________________________ Valgrind-users mailing list Valgrind-users@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/valgrind-users