leaks pid | partial-executable-name [-nocontext] [-nostacks] [-exclude symbol] [-trace address]
Identifies leaked memory -- memory that the application has allocated, but has been lost and cannot be freed.
Examines a process's memory for values that may be pointers to malloc-allocated buffers.
For each leaked buffer , leaks outputs the address of the leaked memory and its size.
If leaks can determine that the object is an instance of an Objective-C, CoreFoundation, or C++ class, or a CFType, it specifies the name and type of
the class, and the binary image that implements the class. It then outputs a string or hexadecimal representation of the contents of the memory, unless -nocontext
was specified.
If the MallocStackLogging
environment variable was set when the application was launched, leaks also outputs a stack trace
describing where the buffer was allocated.
OPTIONS
-nocontext | Do not print the string or hex representation of leaked memory. Although that information can be useful for recognizing the contents of the buffer and understanding why it might be leaked, it can provide overwhelming detail, and could expose confidential information. | ||||
-nostacks |
leaks
may detect more leaks if the target process is run with the MallocScribble
environment variable. If this
variable is set when malloc blocks are deallocated they are filled with 0x55 bytes, overwriting data such
as pointers remaining in those blocks. This reduces the number of false pointers remaining in the process memory.
The Xcode developer tools includes Instruments
, a graphical application that can give information similar to that provided
by leaks. The Allocations
instrument graphically displays dynamic, real-time information about the object and memory use in an
application, including backtraces of where the allocations occurred.
> sudo leaks 1842 Process: mdworker [1842] Path: /System/Library/Frameworks/CoreServices.framework/Versions/A/Frameworks/Metadata.framework/Versions/A/Support/mdworker Load Address: 0x105131000 Identifier: mdworker Version: ??? Code Type: X86-64 Parent Process: launchd [1] Date/Time: 2016-11-22 16:56:18.464 -0500 Launch Time: 2016-11-22 16:56:02.665 -0500 OS Version: Mac OS X 10.11.6 (15G1108) Report Version: 7 Analysis Tool: /Applications/Xcode.app/Contents/Developer/usr/bin/leaks Analysis Tool Version: Xcode 8.1 (8B62) ---- leaks Report Version: 2.0 Process 1842: 2679 nodes malloced for 406 KB Process 1842: 1 leak for 192 total leaked bytes. Leak: 0x7fa8c0d03790 size=192 zone: DefaultMallocZone_0x1051c5000 OS_dispatch_source ObjC libdispatch.dylib 0x7783b420 0x00007fff 0x00000001 0x00000000 ..w............ 0x89abcdef 0xffffffff 0xc0c26a00 0x00007fa8 .........j...... 0x00000000 0x00000000 0x00000000 0x00000000 ................ 0x00000000 0x00000000 0x00000000 0x00000000 ................ 0x00000000 0x00000000 0x00000000 0x00000000 ................ 0x00000001 0x00000000 0x00000000 0x00000000 ................ 0x00000000 0x00000000 0xffffffff 0xffffffff ................ 0x0000001f 0x00000000 0x997195bc 0x00007fff ..........q..... ...
> sudo leaks -nocontext -nostacks 436 Password: Process: sysmond [436] Path: /usr/libexec/sysmond Load Address: 0x10685e000 Identifier: sysmond Version: ??? Code Type: X86-64 Parent Process: launchd [1] Date/Time: 2016-11-22 16:33:33.958 -0500 Launch Time: 2016-11-21 16:59:34.408 -0500 OS Version: Mac OS X 10.11.6 (15G1108) Report Version: 7 Analysis Tool: /Applications/Xcode.app/Contents/Developer/usr/bin/leaks Analysis Tool Version: Xcode 8.1 (8B62) ---- leaks Report Version: 2.0 Process 436: 5758 nodes malloced for 426 KB Process 436: 0 leaks for 0 total leaked bytes