ADC Home > Reference Library > Reference > Mac OS X > Mac OS X Man Pages

 

This document is a Mac OS X manual page. Manual pages are a command-line technology for providing documentation. You can view these manual pages locally using the man(1) command. These manual pages come from many different sources, and thus, have a variety of writing styles.

This manual page is associated with the Mac OS X developer tools. The software or headers described may not be present on your Mac OS X installation until you install the developer tools package. This package is available on your Mac OS X installation DVD, and the latest versions can be downloaded from developer.apple.com.

For more information about the manual page format, see the manual page for manpages(5).



malloc_history(1)         BSD General Commands Manual        malloc_history(1)

NAME
     malloc_history -- Show the malloc allocations that the process has performed

SYNOPSIS
     malloc_history pid address
     malloc_history pid -all_by_size
     malloc_history pid -all_by_count

DESCRIPTION
     malloc_history inspects a given process and lists the malloc allocations performed by it.  malloc_his-tory malloc_history
     tory relies on information provided by the standard malloc library when debugging options have been
     turned on.

     By specifying an address, malloc_history lists the allocations and deallocations that have manipulated
     a buffer at that address.  For each allocation, a stack trace describing who called malloc or free is
     listed.

     Alternatively, the -all_by_size and -all_by_count options will list all allocations.  Frequent alloca-tions allocations
     tions from the same point in the program (that is, the same call stack) are grouped together, and out-put output
     put presented either from largest allocations to smallest, or most allocations to least.

     All modes require the standard malloc library's debugging facility to be turned on.  To do this, set
     the environment variable MallocStackLogging to 1 in the shell that will run the program.  To be able to
     examine allocations by address, also set the environment variable MallocStackLoggingNoCompact to 1.

     malloc_history is particularly useful for tracking down memory smashers.  Run the program to be
     inspected with MallocStackLogging and MallocStackLoggingNoCompact defined.  Also set the environment
     variable MallocScribble; this causes the malloc library to overwrite freed memory with a well-known
     value (0x55), and occasionally checks freed buffers to make sure the memory has not been overwritten
     since it was cleared.  When malloc detects the memory has been written, it will print out a warning
     that the buffer was modified after being freed.  You can then use malloc_history to find who allocated
     and freed memory at that address, and thus deduce what parts of the code might still have a pointer to
     the freed structure.

SEE ALSO
     malloc(3), heap(1), leaks(1), vmmap(1)

     The developer tools for the system also include a graphical application, /Developer/Applica-tions/Instruments.app, /Developer/Applications/Instruments.app,
     tions/Instruments.app, that provides instruments that give information similar to that provided by
     malloc_history. The ObjectAlloc instrument graphically displays dynamic, real-time information about
     the object and memory use in an application, including backtraces of where the allocations occured.

BSD                             March 15, 2007                             BSD

Did this document help you?
Yes: Tell us what works for you.
It’s good, but: Report typos, inaccuracies, and so forth.
It wasn’t helpful: Tell us what would have helped.