FreeBSD Port: valgrind-snapshot-352_3
Charles Swiger
cswiger at mac.com
Thu Apr 7 10:59:21 PDT 2005
On Apr 6, 2005, at 1:20 PM, Sebastien Poirier wrote:
> I would like to know if your port is aimed for Mac OS X too.
> We are looking for a memory debug tools for Mac OS X and Valgrind
> seems to be the best for this purpose.
Hi, Sebastian--
The "leaks" command which comes with OS X is pretty darn useful:
% cat /tmp/foo.c
#include <stdlib.h>
void bad(int size)
{
int x;
char *leaky;
leaky = malloc(size);
for (x = 0; x < size; x++)
leaky[x] = (char) x + 'a';
leaky = NULL;
}
main()
{
bad(10);
bad(20);
sleep(100);
}
% MallocStackLogging=1 /tmp/foo &
malloc[16451]: recording stacks using standard recorder
% leaks foo
Process 16451: 10 nodes malloced for 1 KB
Process 16451: 2 leaks for 48 total leaked bytes.
Leak: 0x00100150 size=32 string 'abcdefghijklmnopqrst'
Call stack: [thread 1a27]: | 0x0 | start | _start | main | bad
| malloc | malloc_zone_malloc
Leak: 0x00100140 size=16 string 'abcdefghij'
Call stack: [thread 1a27]: | 0x0 | start | _start | main | bad
| malloc | malloc_zone_malloc
Even if you don't run with that ENV variable set, simply seeing the
size and the contents of leaked memory is often enough to help ("do you
know how big your structures are?" :-), but having the call stack
responsible for the allocation of the memory is a godsend.
--
-Chuck
More information about the freebsd-ports
mailing list