From: Greg P. <gp...@us...> - 2006-07-30 04:55:08
|
Lots of Mac OS X code does the moral equivalent of this: void *p = malloc(1); size_t size = malloc_usable_size(p); memset(p, 0, size); Memcheck reports "invalid write" errors for the memset(). The problem is that Memcheck's malloc replacement marks only the requested byte count as usable, but Valgrind's malloc_usable_size() implementation returns the actual allocated size, which may be bigger. In this case, Memcheck marks 1 byte of p as valid, but malloc_usable_size(p) returns 8 (or 16, depending on the minimum allocation size). One fix would be to have Memcheck wrap malloc_usable_size() and return the requested size only. Another would be for Memcheck to mark the full allocated size as usable, but that would tend to mask small overrun errors. -- Greg Parker gp...@us... |