1*8d67ca89SAndroid Build Coastguard WorkerMalloc Debug 2*8d67ca89SAndroid Build Coastguard Worker============ 3*8d67ca89SAndroid Build Coastguard Worker 4*8d67ca89SAndroid Build Coastguard WorkerMalloc debug is a method of debugging native memory problems. It can help 5*8d67ca89SAndroid Build Coastguard Workerdetect memory corruption, memory leaks, and use after free issues. 6*8d67ca89SAndroid Build Coastguard Worker 7*8d67ca89SAndroid Build Coastguard WorkerThis documentation describes how to enable this feature on Android N or later 8*8d67ca89SAndroid Build Coastguard Workerversions of the Android OS. (See the "Examples" section.) 9*8d67ca89SAndroid Build Coastguard Worker 10*8d67ca89SAndroid Build Coastguard WorkerThe documentation for malloc debug on older versions of Android is 11*8d67ca89SAndroid Build Coastguard Worker[here](README_marshmallow_and_earlier.md). 12*8d67ca89SAndroid Build Coastguard Worker 13*8d67ca89SAndroid Build Coastguard WorkerWhen malloc debug is enabled, it works by adding a shim layer that replaces 14*8d67ca89SAndroid Build Coastguard Workerthe normal allocation calls. The replaced calls are: 15*8d67ca89SAndroid Build Coastguard Worker 16*8d67ca89SAndroid Build Coastguard Worker* `malloc` 17*8d67ca89SAndroid Build Coastguard Worker* `free` 18*8d67ca89SAndroid Build Coastguard Worker* `calloc` 19*8d67ca89SAndroid Build Coastguard Worker* `realloc` 20*8d67ca89SAndroid Build Coastguard Worker* `posix_memalign` 21*8d67ca89SAndroid Build Coastguard Worker* `memalign` 22*8d67ca89SAndroid Build Coastguard Worker* `aligned_alloc` 23*8d67ca89SAndroid Build Coastguard Worker* `malloc_usable_size` 24*8d67ca89SAndroid Build Coastguard Worker 25*8d67ca89SAndroid Build Coastguard WorkerOn 32 bit systems, these two deprecated functions are also replaced: 26*8d67ca89SAndroid Build Coastguard Worker 27*8d67ca89SAndroid Build Coastguard Worker* `pvalloc` 28*8d67ca89SAndroid Build Coastguard Worker* `valloc` 29*8d67ca89SAndroid Build Coastguard Worker 30*8d67ca89SAndroid Build Coastguard WorkerAny errors detected by the library are reported in the log. 31*8d67ca89SAndroid Build Coastguard Worker 32*8d67ca89SAndroid Build Coastguard WorkerNOTE: There is a small behavioral change beginning in P for realloc. 33*8d67ca89SAndroid Build Coastguard WorkerBefore, a realloc from one size to a smaller size would not update the 34*8d67ca89SAndroid Build Coastguard Workerbacktrace related to the allocation. Starting in P, every single realloc 35*8d67ca89SAndroid Build Coastguard Workercall changes the backtrace for the pointer no matter whether the pointer 36*8d67ca89SAndroid Build Coastguard Workerreturned has changed or not. 37*8d67ca89SAndroid Build Coastguard Worker 38*8d67ca89SAndroid Build Coastguard Worker 39*8d67ca89SAndroid Build Coastguard WorkerControlling Malloc Debug Behavior 40*8d67ca89SAndroid Build Coastguard Worker--------------------------------- 41*8d67ca89SAndroid Build Coastguard WorkerMalloc debug is controlled by individual options. Each option can be enabled 42*8d67ca89SAndroid Build Coastguard Workerindividually, or in a group of other options. Every single option can be 43*8d67ca89SAndroid Build Coastguard Workercombined with every other option. 44*8d67ca89SAndroid Build Coastguard Worker 45*8d67ca89SAndroid Build Coastguard WorkerOption Descriptions 46*8d67ca89SAndroid Build Coastguard Worker------------------- 47*8d67ca89SAndroid Build Coastguard Worker### front\_guard[=SIZE\_BYTES] 48*8d67ca89SAndroid Build Coastguard WorkerEnables a small buffer placed before the allocated data. This is an attempt 49*8d67ca89SAndroid Build Coastguard Workerto find memory corruption occuring to a region before the original allocation. 50*8d67ca89SAndroid Build Coastguard WorkerOn first allocation, this front guard is written with a specific pattern (0xaa). 51*8d67ca89SAndroid Build Coastguard WorkerWhen the allocation is freed, the guard is checked to verify it has not been 52*8d67ca89SAndroid Build Coastguard Workermodified. If any part of the front guard is modified, an error will be reported 53*8d67ca89SAndroid Build Coastguard Workerin the log indicating what bytes changed. 54*8d67ca89SAndroid Build Coastguard Worker 55*8d67ca89SAndroid Build Coastguard WorkerIf the backtrace option is also enabled, then any error message will include 56*8d67ca89SAndroid Build Coastguard Workerthe backtrace of the allocation site. 57*8d67ca89SAndroid Build Coastguard Worker 58*8d67ca89SAndroid Build Coastguard WorkerIf SIZE\_BYTES is present, it indicates the number of bytes in the guard. 59*8d67ca89SAndroid Build Coastguard WorkerThe default is 32 bytes, the max bytes is 16384. SIZE\_BYTES will be 60*8d67ca89SAndroid Build Coastguard Workerpadded so that it is a multiple of 8 bytes on 32 bit systems and 16 bytes 61*8d67ca89SAndroid Build Coastguard Workeron 64 bit systems to make sure that the allocation returned is aligned 62*8d67ca89SAndroid Build Coastguard Workerproperly. 63*8d67ca89SAndroid Build Coastguard Worker 64*8d67ca89SAndroid Build Coastguard WorkerThis option adds a special header to all allocations that contains the guard 65*8d67ca89SAndroid Build Coastguard Workerand information about the original allocation. 66*8d67ca89SAndroid Build Coastguard Worker 67*8d67ca89SAndroid Build Coastguard WorkerExample error: 68*8d67ca89SAndroid Build Coastguard Worker 69*8d67ca89SAndroid Build Coastguard Worker 04-10 12:00:45.621 7412 7412 E malloc_debug: +++ ALLOCATION 0x12345678 SIZE 100 HAS A CORRUPTED FRONT GUARD 70*8d67ca89SAndroid Build Coastguard Worker 04-10 12:00:45.622 7412 7412 E malloc_debug: allocation[-32] = 0x00 (expected 0xaa) 71*8d67ca89SAndroid Build Coastguard Worker 04-10 12:00:45.622 7412 7412 E malloc_debug: allocation[-15] = 0x02 (expected 0xaa) 72*8d67ca89SAndroid Build Coastguard Worker 73*8d67ca89SAndroid Build Coastguard Worker### rear\_guard[=SIZE\_BYTES] 74*8d67ca89SAndroid Build Coastguard WorkerEnables a small buffer placed after the allocated data. This is an attempt 75*8d67ca89SAndroid Build Coastguard Workerto find memory corruption occuring to a region after the original allocation. 76*8d67ca89SAndroid Build Coastguard WorkerOn first allocation, this rear guard is written with a specific pattern (0xbb). 77*8d67ca89SAndroid Build Coastguard WorkerWhen the allocation is freed, the guard is checked to verify it has not been 78*8d67ca89SAndroid Build Coastguard Workermodified. If any part of the rear guard is modified, an error will be reported 79*8d67ca89SAndroid Build Coastguard Workerin the log indicating what bytes changed. 80*8d67ca89SAndroid Build Coastguard Worker 81*8d67ca89SAndroid Build Coastguard WorkerIf SIZE\_BYTES is present, it indicates the number of bytes in the guard. 82*8d67ca89SAndroid Build Coastguard WorkerThe default is 32 bytes, the max bytes is 16384. 83*8d67ca89SAndroid Build Coastguard Worker 84*8d67ca89SAndroid Build Coastguard WorkerThis option adds a special header to all allocations that contains 85*8d67ca89SAndroid Build Coastguard Workerinformation about the original allocation. 86*8d67ca89SAndroid Build Coastguard Worker 87*8d67ca89SAndroid Build Coastguard WorkerExample error: 88*8d67ca89SAndroid Build Coastguard Worker 89*8d67ca89SAndroid Build Coastguard Worker 04-10 12:00:45.621 7412 7412 E malloc_debug: +++ ALLOCATION 0x12345678 SIZE 100 HAS A CORRUPTED REAR GUARD 90*8d67ca89SAndroid Build Coastguard Worker 04-10 12:00:45.622 7412 7412 E malloc_debug: allocation[130] = 0xbf (expected 0xbb) 91*8d67ca89SAndroid Build Coastguard Worker 04-10 12:00:45.622 7412 7412 E malloc_debug: allocation[131] = 0x00 (expected 0xbb) 92*8d67ca89SAndroid Build Coastguard Worker 93*8d67ca89SAndroid Build Coastguard Worker### guard[=SIZE\_BYTES] 94*8d67ca89SAndroid Build Coastguard WorkerEnables both a front guard and a rear guard on all allocations. 95*8d67ca89SAndroid Build Coastguard Worker 96*8d67ca89SAndroid Build Coastguard WorkerIf SIZE\_BYTES is present, it indicates the number of bytes in both guards. 97*8d67ca89SAndroid Build Coastguard WorkerThe default is 32 bytes, the max bytes is 16384. 98*8d67ca89SAndroid Build Coastguard Worker 99*8d67ca89SAndroid Build Coastguard Worker### backtrace[=MAX\_FRAMES] 100*8d67ca89SAndroid Build Coastguard WorkerEnable capturing the backtrace of each allocation site. 101*8d67ca89SAndroid Build Coastguard WorkerThis option will slow down allocations by an order of magnitude. If the 102*8d67ca89SAndroid Build Coastguard Workersystem runs too slowly with this option enabled, decreasing the maximum number 103*8d67ca89SAndroid Build Coastguard Workerof frames captured will speed the allocations up. 104*8d67ca89SAndroid Build Coastguard Worker 105*8d67ca89SAndroid Build Coastguard WorkerNote that any backtrace frames that occur within the malloc backtrace library 106*8d67ca89SAndroid Build Coastguard Workeritself are not recorded. 107*8d67ca89SAndroid Build Coastguard Worker 108*8d67ca89SAndroid Build Coastguard WorkerIf MAX\_FRAMES is present, it indicates the maximum number of frames to 109*8d67ca89SAndroid Build Coastguard Workercapture in a backtrace. The default is 16 frames, the maximumum value 110*8d67ca89SAndroid Build Coastguard Workerthis can be set to is 256. 111*8d67ca89SAndroid Build Coastguard Worker 112*8d67ca89SAndroid Build Coastguard WorkerBefore P, this option adds a special header to all allocations that contains 113*8d67ca89SAndroid Build Coastguard Workerthe backtrace and information about the original allocation. After that, this 114*8d67ca89SAndroid Build Coastguard Workeroption will not add a special header. 115*8d67ca89SAndroid Build Coastguard Worker 116*8d67ca89SAndroid Build Coastguard WorkerAs of P, this option will also enable dumping backtrace heap data to a 117*8d67ca89SAndroid Build Coastguard Workerfile when the process receives the signal SIGRTMAX - 17 ( which is 47 on 118*8d67ca89SAndroid Build Coastguard WorkerAndroid devices). The format of this dumped data is the same format as 119*8d67ca89SAndroid Build Coastguard Workerthat dumped when running am dumpheap -n. The default is to dump this data 120*8d67ca89SAndroid Build Coastguard Workerto the file /data/local/tmp/backtrace\_heap.**PID**.txt. This is useful when 121*8d67ca89SAndroid Build Coastguard Workerused with native only executables that run for a while since these processes 122*8d67ca89SAndroid Build Coastguard Workerare not spawned from a zygote process. 123*8d67ca89SAndroid Build Coastguard Worker 124*8d67ca89SAndroid Build Coastguard WorkerNote that when the signal is received, the heap is not dumped until the next 125*8d67ca89SAndroid Build Coastguard Workermalloc/free occurs. 126*8d67ca89SAndroid Build Coastguard Worker 127*8d67ca89SAndroid Build Coastguard Worker### backtrace\_enable\_on\_signal[=MAX\_FRAMES] 128*8d67ca89SAndroid Build Coastguard WorkerEnable capturing the backtrace of each allocation site. If the 129*8d67ca89SAndroid Build Coastguard Workerbacktrace capture is toggled when the process receives the signal 130*8d67ca89SAndroid Build Coastguard WorkerSIGRTMAX - 19 (which is 45 on Android devices). When this 131*8d67ca89SAndroid Build Coastguard Workeroption is used alone, backtrace capture starts out disabled until the signal 132*8d67ca89SAndroid Build Coastguard Workeris received. If both this option and the backtrace option are set, then 133*8d67ca89SAndroid Build Coastguard Workerbacktrace capture is enabled until the signal is received. 134*8d67ca89SAndroid Build Coastguard Worker 135*8d67ca89SAndroid Build Coastguard WorkerIf MAX\_FRAMES is present, it indicates the maximum number of frames to 136*8d67ca89SAndroid Build Coastguard Workercapture in a backtrace. The default is 16 frames, the maximumum value 137*8d67ca89SAndroid Build Coastguard Workerthis can be set to is 256. 138*8d67ca89SAndroid Build Coastguard Worker 139*8d67ca89SAndroid Build Coastguard WorkerBefore P, this option adds a special header to all allocations that contains 140*8d67ca89SAndroid Build Coastguard Workerthe backtrace and information about the original allocation. After that, this 141*8d67ca89SAndroid Build Coastguard Workeroption will not add a special header. 142*8d67ca89SAndroid Build Coastguard Worker 143*8d67ca89SAndroid Build Coastguard Worker### backtrace\_dump\_on\_exit 144*8d67ca89SAndroid Build Coastguard WorkerAs of P, when the backtrace option has been enabled, this causes the backtrace 145*8d67ca89SAndroid Build Coastguard Workerdump heap data to be dumped to a file when the program exits. If the backtrace 146*8d67ca89SAndroid Build Coastguard Workeroption has not been enabled, this does nothing. The default is to dump this 147*8d67ca89SAndroid Build Coastguard Workerto the file named /data/local/tmp/backtrace\_heap.**PID**.exit.txt. 148*8d67ca89SAndroid Build Coastguard Worker 149*8d67ca89SAndroid Build Coastguard WorkerThe file location can be changed by setting the backtrace\_dump\_prefix 150*8d67ca89SAndroid Build Coastguard Workeroption. 151*8d67ca89SAndroid Build Coastguard Worker 152*8d67ca89SAndroid Build Coastguard Worker### backtrace\_dump\_prefix 153*8d67ca89SAndroid Build Coastguard WorkerAs of P, when one of the backtrace options has been enabled, this sets the 154*8d67ca89SAndroid Build Coastguard Workerprefix used for dumping files when the signal SIGRTMAX - 17 is received or when 155*8d67ca89SAndroid Build Coastguard Workerthe program exits and backtrace\_dump\_on\_exit is set. 156*8d67ca89SAndroid Build Coastguard Worker 157*8d67ca89SAndroid Build Coastguard WorkerThe default is /data/local/tmp/backtrace\_heap. 158*8d67ca89SAndroid Build Coastguard Worker 159*8d67ca89SAndroid Build Coastguard WorkerWhen this value is changed from the default, then the filename chosen 160*8d67ca89SAndroid Build Coastguard Workeron the signal will be backtrace\_dump\_prefix.**PID**.txt. The filename chosen 161*8d67ca89SAndroid Build Coastguard Workerwhen the program exits will be backtrace\_dump\_prefix.**PID**.exit.txt. 162*8d67ca89SAndroid Build Coastguard Worker 163*8d67ca89SAndroid Build Coastguard Worker### backtrace\_min\_size=ALLOCATION\_SIZE\_BYTES 164*8d67ca89SAndroid Build Coastguard WorkerAs of U, setting this in combination with the backtrace option means 165*8d67ca89SAndroid Build Coastguard Workerthat only allocations of a size greater than or equal to 166*8d67ca89SAndroid Build Coastguard Worker**ALLOCATION\_SIZE\_BYTES** will be backtraced. When used in combination 167*8d67ca89SAndroid Build Coastguard Workerwith the backtrace\_max\_size option, then allocations greater than or 168*8d67ca89SAndroid Build Coastguard Workerequal to backtrace\_min\_size and less than or equal to 169*8d67ca89SAndroid Build Coastguard Workerbacktrace\_max\_size will be backtraced. The backtrace\_size option 170*8d67ca89SAndroid Build Coastguard Workeroverrides this option, and should not be used at the same time. 171*8d67ca89SAndroid Build Coastguard Worker 172*8d67ca89SAndroid Build Coastguard WorkerThis option can also be used in combination with other tools such 173*8d67ca89SAndroid Build Coastguard Workeras [libmemunreachable](https://android.googlesource.com/platform/system/memory/libmemunreachable/+/main/README.md) 174*8d67ca89SAndroid Build Coastguard Workerto only get backtraces for sizes of allocations listed as being leaked. 175*8d67ca89SAndroid Build Coastguard Worker 176*8d67ca89SAndroid Build Coastguard Worker### backtrace\_max\_size=ALLOCATION\_SIZE\_BYTES 177*8d67ca89SAndroid Build Coastguard WorkerAs of U, setting this in combination with the backtrace option means 178*8d67ca89SAndroid Build Coastguard Workerthat only allocations of a size less than or equal to 179*8d67ca89SAndroid Build Coastguard Worker**ALLOCATION\_SIZE\_BYTES** will be backtraced. When used in combination 180*8d67ca89SAndroid Build Coastguard Workerwith the backtrace\_min\_size option, then allocations greater than or 181*8d67ca89SAndroid Build Coastguard Workerequal to backtrace\_min\_size and less than or equal to 182*8d67ca89SAndroid Build Coastguard Workerbacktrace\_max\_size will be backtraced. The backtrace\_size option 183*8d67ca89SAndroid Build Coastguard Workeroverrides this option, and should not be used at the same time. 184*8d67ca89SAndroid Build Coastguard Worker 185*8d67ca89SAndroid Build Coastguard WorkerThis option can also be used in combination with other tools such 186*8d67ca89SAndroid Build Coastguard Workeras [libmemunreachable](https://android.googlesource.com/platform/system/memory/libmemunreachable/+/main/README.md) 187*8d67ca89SAndroid Build Coastguard Workerto only get backtraces for sizes of allocations listed as being leaked. 188*8d67ca89SAndroid Build Coastguard Worker 189*8d67ca89SAndroid Build Coastguard Worker### backtrace\_size=ALLOCATION\_SIZE\_BYTES 190*8d67ca89SAndroid Build Coastguard WorkerAs of U, setting this in combination with the backtrace option means 191*8d67ca89SAndroid Build Coastguard Workerthat only allocations of size **ALLOCATION\_SIZE\_BYTES** will be backtraced. 192*8d67ca89SAndroid Build Coastguard WorkerThis option overrides the backtrace\_min\_size and the backtrace\_max\_size. 193*8d67ca89SAndroid Build Coastguard Worker 194*8d67ca89SAndroid Build Coastguard WorkerThis option can also be used in combination with other tools such 195*8d67ca89SAndroid Build Coastguard Workeras [libmemunreachable](https://android.googlesource.com/platform/system/memory/libmemunreachable/+/main/README.md) 196*8d67ca89SAndroid Build Coastguard Workerto only get backtraces for sizes of allocations listed as being leaked. 197*8d67ca89SAndroid Build Coastguard Worker 198*8d67ca89SAndroid Build Coastguard Worker### backtrace\_full 199*8d67ca89SAndroid Build Coastguard WorkerAs of Q, any time that a backtrace is gathered, a different algorithm is used 200*8d67ca89SAndroid Build Coastguard Workerthat is extra thorough and can unwind through Java frames. This will run 201*8d67ca89SAndroid Build Coastguard Workerslower than the normal backtracing function. 202*8d67ca89SAndroid Build Coastguard Worker 203*8d67ca89SAndroid Build Coastguard Worker### bt, bt\_dmp\_on\_ex, bt\_dmp\_pre, bt\_en\_on\_sig, bt\_full, bt\_max\_sz, bt\_min\_sz, bt\_sz 204*8d67ca89SAndroid Build Coastguard WorkerAs of U, add shorter aliases for backtrace related options to avoid property length restrictions. 205*8d67ca89SAndroid Build Coastguard Worker 206*8d67ca89SAndroid Build Coastguard Worker| Alias | Option | 207*8d67ca89SAndroid Build Coastguard Worker|:----------------|:------------------------------| 208*8d67ca89SAndroid Build Coastguard Worker| bt | backtrace | 209*8d67ca89SAndroid Build Coastguard Worker| bt\_dmp\_on\_ex | backtrace\_dump\_on\_exit | 210*8d67ca89SAndroid Build Coastguard Worker| bt\_dmp\_pre | backtrace\_dump\_prefix | 211*8d67ca89SAndroid Build Coastguard Worker| bt\_en\_on\_sig | backtrace\_enable\_on\_signal | 212*8d67ca89SAndroid Build Coastguard Worker| bt\_full | backtrace\_full | 213*8d67ca89SAndroid Build Coastguard Worker| bt\_max\_sz | backtrace\_max\_size | 214*8d67ca89SAndroid Build Coastguard Worker| bt\_min\_sz | backtrace\_min\_size | 215*8d67ca89SAndroid Build Coastguard Worker| bt\_sz | backtrace\_size | 216*8d67ca89SAndroid Build Coastguard Worker 217*8d67ca89SAndroid Build Coastguard Worker### check\_unreachable\_on\_signal 218*8d67ca89SAndroid Build Coastguard WorkerAs of Android U, this option will trigger a check for unreachable memory 219*8d67ca89SAndroid Build Coastguard Workerin a process. Specifically, if the signal SIGRTMAX - 16 (which is 48 on 220*8d67ca89SAndroid Build Coastguard WorkerAndroid devices). The best way to see the exact signal being used is to 221*8d67ca89SAndroid Build Coastguard Workerenable the verbose option then look at the log for the message: 222*8d67ca89SAndroid Build Coastguard Worker 223*8d67ca89SAndroid Build Coastguard Worker Run: 'kill -48 <PID>' to check for unreachable memory. 224*8d67ca89SAndroid Build Coastguard Worker 225*8d67ca89SAndroid Build Coastguard WorkerWhen the signal is received, the actual unreachable check only triggers 226*8d67ca89SAndroid Build Coastguard Workeron the next allocation that happens in the process (malloc/free, etc). 227*8d67ca89SAndroid Build Coastguard Worker 228*8d67ca89SAndroid Build Coastguard WorkerIf a process is not doing any allocations, it can be forced to trigger when 229*8d67ca89SAndroid Build Coastguard Workerrunning: 230*8d67ca89SAndroid Build Coastguard Worker 231*8d67ca89SAndroid Build Coastguard Worker debuggerd -b <PID> 232*8d67ca89SAndroid Build Coastguard Worker 233*8d67ca89SAndroid Build Coastguard Worker**NOTE**: The unreachable check can fail for protected processes, so it 234*8d67ca89SAndroid Build Coastguard Workermight be necessary to run: 235*8d67ca89SAndroid Build Coastguard Worker 236*8d67ca89SAndroid Build Coastguard Worker setenforce 0 237*8d67ca89SAndroid Build Coastguard Worker 238*8d67ca89SAndroid Build Coastguard WorkerTo get the unreachable data. 239*8d67ca89SAndroid Build Coastguard Worker 240*8d67ca89SAndroid Build Coastguard Worker### fill\_on\_alloc[=MAX\_FILLED\_BYTES] 241*8d67ca89SAndroid Build Coastguard WorkerAny allocation routine, other than calloc, will result in the allocation being 242*8d67ca89SAndroid Build Coastguard Workerfilled with the value 0xeb. When doing a realloc to a larger size, the bytes 243*8d67ca89SAndroid Build Coastguard Workerabove the original usable size will be set to 0xeb. 244*8d67ca89SAndroid Build Coastguard Worker 245*8d67ca89SAndroid Build Coastguard WorkerIf MAX\_FILLED\_BYTES is present, it will only fill up to the specified number 246*8d67ca89SAndroid Build Coastguard Workerof bytes in the allocation. The default is to fill the entire allocation. 247*8d67ca89SAndroid Build Coastguard Worker 248*8d67ca89SAndroid Build Coastguard Worker### fill\_on\_free[=MAX\_FILLED\_BYTES] 249*8d67ca89SAndroid Build Coastguard WorkerWhen an allocation is freed, fill it with 0xef. 250*8d67ca89SAndroid Build Coastguard Worker 251*8d67ca89SAndroid Build Coastguard WorkerIf MAX\_FILLED\_BYTES is present, it will only fill up to the specified number 252*8d67ca89SAndroid Build Coastguard Workerof bytes in the allocation. The default is to fill the entire allocation. 253*8d67ca89SAndroid Build Coastguard Worker 254*8d67ca89SAndroid Build Coastguard Worker### fill[=MAX\_FILLED\_BYTES] 255*8d67ca89SAndroid Build Coastguard WorkerThis enables both the fill\_on\_alloc option and the fill\_on\_free option. 256*8d67ca89SAndroid Build Coastguard Worker 257*8d67ca89SAndroid Build Coastguard WorkerIf MAX\_FILLED\_BYTES is present, it will only fill up to the specified number 258*8d67ca89SAndroid Build Coastguard Workerof bytes in the allocation. The default is to fill the entire allocation. 259*8d67ca89SAndroid Build Coastguard Worker 260*8d67ca89SAndroid Build Coastguard Worker### expand\_alloc[=EXPAND\_BYTES] 261*8d67ca89SAndroid Build Coastguard WorkerAdd an extra amount to allocate for every allocation. 262*8d67ca89SAndroid Build Coastguard Worker 263*8d67ca89SAndroid Build Coastguard WorkerIf XX is present, it is the number of bytes to expand the allocation by. 264*8d67ca89SAndroid Build Coastguard WorkerThe default is 16 bytes, the max bytes is 16384. 265*8d67ca89SAndroid Build Coastguard Worker 266*8d67ca89SAndroid Build Coastguard Worker### free\_track[=ALLOCATION\_COUNT] 267*8d67ca89SAndroid Build Coastguard WorkerWhen a pointer is freed, do not free the memory right away, but add it to 268*8d67ca89SAndroid Build Coastguard Workera list of freed allocations. In addition to being added to the list, the 269*8d67ca89SAndroid Build Coastguard Workerentire allocation is filled with the value 0xef, and the backtrace at 270*8d67ca89SAndroid Build Coastguard Workerthe time of the free is recorded. The backtrace recording is completely 271*8d67ca89SAndroid Build Coastguard Workerseparate from the backtrace option, and happens automatically if this 272*8d67ca89SAndroid Build Coastguard Workeroption is enabled. By default, a maximum of 16 frames will be recorded, 273*8d67ca89SAndroid Build Coastguard Workerbut this value can be changed using the free\_track\_backtrace\_num\_frames 274*8d67ca89SAndroid Build Coastguard Workeroption. It can also be completely disabled by setting the option to zero. 275*8d67ca89SAndroid Build Coastguard WorkerSee the full description of this option below. 276*8d67ca89SAndroid Build Coastguard Worker 277*8d67ca89SAndroid Build Coastguard WorkerWhen the list is full, an allocation is removed from the list and is 278*8d67ca89SAndroid Build Coastguard Workerchecked to make sure that none of the contents have been modified since 279*8d67ca89SAndroid Build Coastguard Workerbeing placed on the list. When the program terminates, all of the allocations 280*8d67ca89SAndroid Build Coastguard Workerleft on the list are verified. 281*8d67ca89SAndroid Build Coastguard Worker 282*8d67ca89SAndroid Build Coastguard WorkerIf ALLOCATION\_COUNT is present, it indicates the total number of allocations 283*8d67ca89SAndroid Build Coastguard Workerin the list. The default is to record 100 freed allocations, the max 284*8d67ca89SAndroid Build Coastguard Workerallocations to record is 16384. 285*8d67ca89SAndroid Build Coastguard Worker 286*8d67ca89SAndroid Build Coastguard WorkerBefore P, this option adds a special header to all allocations that contains 287*8d67ca89SAndroid Build Coastguard Workerthe backtrace and information about the original allocation. After that, this 288*8d67ca89SAndroid Build Coastguard Workeroption will not add a special header. 289*8d67ca89SAndroid Build Coastguard Worker 290*8d67ca89SAndroid Build Coastguard WorkerExample error: 291*8d67ca89SAndroid Build Coastguard Worker 292*8d67ca89SAndroid Build Coastguard Worker 04-15 12:00:31.304 7412 7412 E malloc_debug: +++ ALLOCATION 0x12345678 USED AFTER FREE 293*8d67ca89SAndroid Build Coastguard Worker 04-15 12:00:31.305 7412 7412 E malloc_debug: allocation[20] = 0xaf (expected 0xef) 294*8d67ca89SAndroid Build Coastguard Worker 04-15 12:00:31.305 7412 7412 E malloc_debug: allocation[99] = 0x12 (expected 0xef) 295*8d67ca89SAndroid Build Coastguard Worker 04-15 12:00:31.305 7412 7412 E malloc_debug: Backtrace at time of free: 296*8d67ca89SAndroid Build Coastguard Worker 04-15 12:00:31.305 7412 7412 E malloc_debug: #00 pc 00029310 /system/lib/libc.so 297*8d67ca89SAndroid Build Coastguard Worker 04-15 12:00:31.305 7412 7412 E malloc_debug: #01 pc 00021438 /system/lib/libc.so (newlocale+160) 298*8d67ca89SAndroid Build Coastguard Worker 04-15 12:00:31.305 7412 7412 E malloc_debug: #02 pc 000a9e38 /system/lib/libc++.so 299*8d67ca89SAndroid Build Coastguard Worker 04-15 12:00:31.305 7412 7412 E malloc_debug: #03 pc 000a28a8 /system/lib/libc++.so 300*8d67ca89SAndroid Build Coastguard Worker 301*8d67ca89SAndroid Build Coastguard WorkerIn addition, there is another type of error message that can occur if 302*8d67ca89SAndroid Build Coastguard Workeran allocation has a special header applied, and the header is corrupted 303*8d67ca89SAndroid Build Coastguard Workerbefore the verification occurs. This is the error message that will be found 304*8d67ca89SAndroid Build Coastguard Workerin the log: 305*8d67ca89SAndroid Build Coastguard Worker 306*8d67ca89SAndroid Build Coastguard Worker 04-15 12:00:31.604 7412 7412 E malloc_debug: +++ ALLOCATION 0x12345678 HAS CORRUPTED HEADER TAG 0x1cc7dc00 AFTER FREE 307*8d67ca89SAndroid Build Coastguard Worker 308*8d67ca89SAndroid Build Coastguard Worker### free\_track\_backtrace\_num\_frames[=MAX\_FRAMES] 309*8d67ca89SAndroid Build Coastguard WorkerThis option only has meaning if free\_track is set. It indicates how many 310*8d67ca89SAndroid Build Coastguard Workerbacktrace frames to capture when an allocation is freed. 311*8d67ca89SAndroid Build Coastguard Worker 312*8d67ca89SAndroid Build Coastguard WorkerIf MAX\_FRAMES is present, it indicates the number of frames to capture. 313*8d67ca89SAndroid Build Coastguard WorkerIf the value is set to zero, then no backtrace will be captured when the 314*8d67ca89SAndroid Build Coastguard Workerallocation is freed. The default is to record 16 frames, the max number of 315*8d67ca89SAndroid Build Coastguard Workerframes to to record is 256. 316*8d67ca89SAndroid Build Coastguard Worker 317*8d67ca89SAndroid Build Coastguard Worker### leak\_track 318*8d67ca89SAndroid Build Coastguard WorkerTrack all live allocations. When the program terminates, all of the live 319*8d67ca89SAndroid Build Coastguard Workerallocations will be dumped to the log. If the backtrace option was enabled, 320*8d67ca89SAndroid Build Coastguard Workerthen the log will include the backtrace of the leaked allocations. This 321*8d67ca89SAndroid Build Coastguard Workeroption is not useful when enabled globally because a lot of programs do not 322*8d67ca89SAndroid Build Coastguard Workerfree everything before the program terminates. 323*8d67ca89SAndroid Build Coastguard Worker 324*8d67ca89SAndroid Build Coastguard WorkerBefore P, this option adds a special header to all allocations that contains 325*8d67ca89SAndroid Build Coastguard Workerthe backtrace and information about the original allocation. After that, this 326*8d67ca89SAndroid Build Coastguard Workeroption will not add a special header. 327*8d67ca89SAndroid Build Coastguard Worker 328*8d67ca89SAndroid Build Coastguard WorkerExample leak error found in the log: 329*8d67ca89SAndroid Build Coastguard Worker 330*8d67ca89SAndroid Build Coastguard Worker 04-15 12:35:33.304 7412 7412 E malloc_debug: +++ APP leaked block of size 100 at 0x2be3b0b0 (leak 1 of 2) 331*8d67ca89SAndroid Build Coastguard Worker 04-15 12:35:33.304 7412 7412 E malloc_debug: Backtrace at time of allocation: 332*8d67ca89SAndroid Build Coastguard Worker 04-15 12:35:33.305 7412 7412 E malloc_debug: #00 pc 00029310 /system/lib/libc.so 333*8d67ca89SAndroid Build Coastguard Worker 04-15 12:35:33.305 7412 7412 E malloc_debug: #01 pc 00021438 /system/lib/libc.so (newlocale+160) 334*8d67ca89SAndroid Build Coastguard Worker 04-15 12:35:33.305 7412 7412 E malloc_debug: #02 pc 000a9e38 /system/lib/libc++.so 335*8d67ca89SAndroid Build Coastguard Worker 04-15 12:35:33.305 7412 7412 E malloc_debug: #03 pc 000a28a8 /system/lib/libc++.so 336*8d67ca89SAndroid Build Coastguard Worker 04-15 12:35:33.305 7412 7412 E malloc_debug: +++ APP leaked block of size 24 at 0x7be32380 (leak 2 of 2) 337*8d67ca89SAndroid Build Coastguard Worker 04-15 12:35:33.305 7412 7412 E malloc_debug: Backtrace at time of allocation: 338*8d67ca89SAndroid Build Coastguard Worker 04-15 12:35:33.305 7412 7412 E malloc_debug: #00 pc 00029310 /system/lib/libc.so 339*8d67ca89SAndroid Build Coastguard Worker 04-15 12:35:33.305 7412 7412 E malloc_debug: #01 pc 00021438 /system/lib/libc.so (newlocale+160) 340*8d67ca89SAndroid Build Coastguard Worker 04-15 12:35:33.305 7412 7412 E malloc_debug: #02 pc 000a9e38 /system/lib/libc++.so 341*8d67ca89SAndroid Build Coastguard Worker 04-15 12:35:33.305 7412 7412 E malloc_debug: #03 pc 000a28a8 /system/lib/libc++.so 342*8d67ca89SAndroid Build Coastguard Worker 343*8d67ca89SAndroid Build Coastguard Worker### log\_allocator\_stats\_on\_signal 344*8d67ca89SAndroid Build Coastguard WorkerAs of Android V, this option will trigger a call to: 345*8d67ca89SAndroid Build Coastguard Worker 346*8d67ca89SAndroid Build Coastguard Worker mallopt(M_LOG_STATS, 0); 347*8d67ca89SAndroid Build Coastguard Worker 348*8d67ca89SAndroid Build Coastguard WorkerWhen a process receives the signal SIGRTMAX - 15 (which is 49 on Android 349*8d67ca89SAndroid Build Coastguard Workerdevices). The mallopt call is not async safe and is not called from the 350*8d67ca89SAndroid Build Coastguard Workersignal handler directly. Instead, the next time any allocation call occurs, 351*8d67ca89SAndroid Build Coastguard Workerthe mallopt is called. 352*8d67ca89SAndroid Build Coastguard Worker 353*8d67ca89SAndroid Build Coastguard Worker### record\_allocs[=TOTAL\_ENTRIES] 354*8d67ca89SAndroid Build Coastguard WorkerKeep track of every allocation/free made on every thread and dump them 355*8d67ca89SAndroid Build Coastguard Workerto a file when the signal SIGRTMAX - 18 (which is 46 on Android devices) 356*8d67ca89SAndroid Build Coastguard Workeris received. 357*8d67ca89SAndroid Build Coastguard Worker 358*8d67ca89SAndroid Build Coastguard WorkerIf TOTAL\_ENTRIES is set, then it indicates the total number of 359*8d67ca89SAndroid Build Coastguard Workerallocation/free records that can be retained. If the number of records 360*8d67ca89SAndroid Build Coastguard Workerreaches the TOTAL\_ENTRIES value, then any further allocations/frees are 361*8d67ca89SAndroid Build Coastguard Workernot recorded. The default value is 8,000,000 and the maximum value this 362*8d67ca89SAndroid Build Coastguard Workercan be set to is 50,000,000. 363*8d67ca89SAndroid Build Coastguard Worker 364*8d67ca89SAndroid Build Coastguard WorkerOnce the signal is received, and the current records are written to the 365*8d67ca89SAndroid Build Coastguard Workerfile, all current records are deleted. Any allocations/frees occuring while 366*8d67ca89SAndroid Build Coastguard Workerthe data is being dumped to the file are ignored. 367*8d67ca89SAndroid Build Coastguard Worker 368*8d67ca89SAndroid Build Coastguard Worker**NOTE**: This option is not available until the O release of Android. 369*8d67ca89SAndroid Build Coastguard Worker 370*8d67ca89SAndroid Build Coastguard WorkerThe allocation data is written in a human readable format. Every line begins 371*8d67ca89SAndroid Build Coastguard Workerwith the THREAD\_ID returned by gettid(), which is the thread that is making 372*8d67ca89SAndroid Build Coastguard Workerthe allocation/free. If a new thread is created, no special line is added 373*8d67ca89SAndroid Build Coastguard Workerto the file. However, when a thread completes, a special entry is added to 374*8d67ca89SAndroid Build Coastguard Workerthe file indicating this. 375*8d67ca89SAndroid Build Coastguard Worker 376*8d67ca89SAndroid Build Coastguard WorkerThe thread complete line is: 377*8d67ca89SAndroid Build Coastguard Worker 378*8d67ca89SAndroid Build Coastguard Worker**THREAD\_ID**: thread\_done 0x0 379*8d67ca89SAndroid Build Coastguard Worker 380*8d67ca89SAndroid Build Coastguard WorkerExample: 381*8d67ca89SAndroid Build Coastguard Worker 382*8d67ca89SAndroid Build Coastguard Worker 187: thread_done 0x0 383*8d67ca89SAndroid Build Coastguard Worker 384*8d67ca89SAndroid Build Coastguard WorkerBelow is how each type of allocation/free call ends up in the file dump. 385*8d67ca89SAndroid Build Coastguard Worker 386*8d67ca89SAndroid Build Coastguard Workerpointer = malloc(size) 387*8d67ca89SAndroid Build Coastguard Worker 388*8d67ca89SAndroid Build Coastguard Worker**THREAD\_ID**: malloc pointer size 389*8d67ca89SAndroid Build Coastguard Worker 390*8d67ca89SAndroid Build Coastguard WorkerExample: 391*8d67ca89SAndroid Build Coastguard Worker 392*8d67ca89SAndroid Build Coastguard Worker 186: malloc 0xb6038060 20 393*8d67ca89SAndroid Build Coastguard Worker 394*8d67ca89SAndroid Build Coastguard Workerfree(pointer) 395*8d67ca89SAndroid Build Coastguard Worker 396*8d67ca89SAndroid Build Coastguard Worker**THREAD\_ID**: free pointer 397*8d67ca89SAndroid Build Coastguard Worker 398*8d67ca89SAndroid Build Coastguard WorkerExample: 399*8d67ca89SAndroid Build Coastguard Worker 400*8d67ca89SAndroid Build Coastguard Worker 186: free 0xb6038060 401*8d67ca89SAndroid Build Coastguard Worker 402*8d67ca89SAndroid Build Coastguard Workerpointer = calloc(nmemb, size) 403*8d67ca89SAndroid Build Coastguard Worker 404*8d67ca89SAndroid Build Coastguard Worker**THREAD\_ID**: calloc pointer nmemb size 405*8d67ca89SAndroid Build Coastguard Worker 406*8d67ca89SAndroid Build Coastguard WorkerExample: 407*8d67ca89SAndroid Build Coastguard Worker 408*8d67ca89SAndroid Build Coastguard Worker 186: calloc 0xb609f080 32 4 409*8d67ca89SAndroid Build Coastguard Worker 410*8d67ca89SAndroid Build Coastguard Workernew\_pointer = realloc(old\_pointer, size) 411*8d67ca89SAndroid Build Coastguard Worker 412*8d67ca89SAndroid Build Coastguard Worker**THREAD\_ID**: realloc new\_pointer old\_pointer size 413*8d67ca89SAndroid Build Coastguard Worker 414*8d67ca89SAndroid Build Coastguard WorkerExample: 415*8d67ca89SAndroid Build Coastguard Worker 416*8d67ca89SAndroid Build Coastguard Worker 186: realloc 0xb609f080 0xb603e9a0 12 417*8d67ca89SAndroid Build Coastguard Worker 418*8d67ca89SAndroid Build Coastguard Workerpointer = memalign(alignment, size) 419*8d67ca89SAndroid Build Coastguard Worker 420*8d67ca89SAndroid Build Coastguard Worker**THREAD\_ID**: memalign pointer alignment size 421*8d67ca89SAndroid Build Coastguard Worker 422*8d67ca89SAndroid Build Coastguard Workerpointer = aligned\_alloc(alignment, size) 423*8d67ca89SAndroid Build Coastguard Worker 424*8d67ca89SAndroid Build Coastguard Worker**THREAD\_ID**: memalign pointer alignment size 425*8d67ca89SAndroid Build Coastguard Worker 426*8d67ca89SAndroid Build Coastguard Workerposix\_memalign(&pointer, alignment, size) 427*8d67ca89SAndroid Build Coastguard Worker 428*8d67ca89SAndroid Build Coastguard Worker**THREAD\_ID**: memalign pointer alignment size 429*8d67ca89SAndroid Build Coastguard Worker 430*8d67ca89SAndroid Build Coastguard WorkerExample: 431*8d67ca89SAndroid Build Coastguard Worker 432*8d67ca89SAndroid Build Coastguard Worker 186: memalign 0x85423660 16 104 433*8d67ca89SAndroid Build Coastguard Worker 434*8d67ca89SAndroid Build Coastguard Workerpointer = valloc(size) 435*8d67ca89SAndroid Build Coastguard Worker 436*8d67ca89SAndroid Build Coastguard Worker**THREAD\_ID**: memalign pointer 4096 size 437*8d67ca89SAndroid Build Coastguard Worker 438*8d67ca89SAndroid Build Coastguard WorkerExample: 439*8d67ca89SAndroid Build Coastguard Worker 440*8d67ca89SAndroid Build Coastguard Worker 186: memalign 0x85423660 4096 112 441*8d67ca89SAndroid Build Coastguard Worker 442*8d67ca89SAndroid Build Coastguard Workerpointer = pvalloc(size) 443*8d67ca89SAndroid Build Coastguard Worker 444*8d67ca89SAndroid Build Coastguard Worker**THREAD\_ID**: memalign pointer 4096 <b>SIZE\_ROUNDED\_UP\_TO\_4096</b> 445*8d67ca89SAndroid Build Coastguard Worker 446*8d67ca89SAndroid Build Coastguard WorkerExample: 447*8d67ca89SAndroid Build Coastguard Worker 448*8d67ca89SAndroid Build Coastguard Worker 186: memalign 0x85423660 4096 8192 449*8d67ca89SAndroid Build Coastguard Worker 450*8d67ca89SAndroid Build Coastguard Worker### record\_allocs\_file[=FILE\_NAME] 451*8d67ca89SAndroid Build Coastguard WorkerThis option only has meaning if record\_allocs is set. It indicates the 452*8d67ca89SAndroid Build Coastguard Workerfile where the recorded allocations will be found. 453*8d67ca89SAndroid Build Coastguard Worker 454*8d67ca89SAndroid Build Coastguard WorkerIf FILE\_NAME is set, then it indicates where the record allocation data 455*8d67ca89SAndroid Build Coastguard Workerwill be placed. 456*8d67ca89SAndroid Build Coastguard Worker 457*8d67ca89SAndroid Build Coastguard Worker**NOTE**: This option is not available until the O release of Android. 458*8d67ca89SAndroid Build Coastguard Worker 459*8d67ca89SAndroid Build Coastguard Worker### record\_allocs\_on\_exit 460*8d67ca89SAndroid Build Coastguard WorkerThis option only has meaning if record\_allocs is set. It indicates that 461*8d67ca89SAndroid Build Coastguard Workerwhen the process terminates, the record file should be created 462*8d67ca89SAndroid Build Coastguard Workerautomatically. 463*8d67ca89SAndroid Build Coastguard Worker 464*8d67ca89SAndroid Build Coastguard WorkerThe only caveat to this option is that when the process terminates, 465*8d67ca89SAndroid Build Coastguard Workerthe file that will contain the records will be the normal file name 466*8d67ca89SAndroid Build Coastguard Workerwith **.PID** appended. Where PID is the pid of the process that has 467*8d67ca89SAndroid Build Coastguard Workerterminated. This is to avoid cases where a number of processes exit 468*8d67ca89SAndroid Build Coastguard Workerat the same time and attempt to write to the same file. 469*8d67ca89SAndroid Build Coastguard Worker 470*8d67ca89SAndroid Build Coastguard Worker**NOTE**: This option is not available until the V release of Android. 471*8d67ca89SAndroid Build Coastguard Worker 472*8d67ca89SAndroid Build Coastguard Worker### verify\_pointers 473*8d67ca89SAndroid Build Coastguard WorkerTrack all live allocations to determine if a pointer is used that does not 474*8d67ca89SAndroid Build Coastguard Workerexist. This option is a lightweight way to verify that all 475*8d67ca89SAndroid Build Coastguard Workerfree/malloc\_usable\_size/realloc calls are passed valid pointers. 476*8d67ca89SAndroid Build Coastguard Worker 477*8d67ca89SAndroid Build Coastguard WorkerExample error: 478*8d67ca89SAndroid Build Coastguard Worker 479*8d67ca89SAndroid Build Coastguard Worker 04-15 12:00:31.304 7412 7412 E malloc_debug: +++ ALLOCATION 0x12345678 UNKNOWN POINTER (free) 480*8d67ca89SAndroid Build Coastguard Worker 04-15 12:00:31.305 7412 7412 E malloc_debug: Backtrace at time of failure: 481*8d67ca89SAndroid Build Coastguard Worker 04-15 12:00:31.305 7412 7412 E malloc_debug: #00 pc 00029310 /system/lib/libc.so 482*8d67ca89SAndroid Build Coastguard Worker 04-15 12:00:31.305 7412 7412 E malloc_debug: #01 pc 00021438 /system/lib/libc.so (newlocale+160) 483*8d67ca89SAndroid Build Coastguard Worker 04-15 12:00:31.305 7412 7412 E malloc_debug: #02 pc 000a9e38 /system/lib/libc++.so 484*8d67ca89SAndroid Build Coastguard Worker 04-15 12:00:31.305 7412 7412 E malloc_debug: #03 pc 000a28a8 /system/lib/libc++.so 485*8d67ca89SAndroid Build Coastguard Worker 486*8d67ca89SAndroid Build Coastguard WorkerWhere the name of the function varies depending on the function that called 487*8d67ca89SAndroid Build Coastguard Workerwith a bad pointer. Only three functions do this checking: free, 488*8d67ca89SAndroid Build Coastguard Workermalloc\_usable\_size, realloc. 489*8d67ca89SAndroid Build Coastguard Worker 490*8d67ca89SAndroid Build Coastguard Worker**NOTE**: This option is not available until the P release of Android. 491*8d67ca89SAndroid Build Coastguard Worker 492*8d67ca89SAndroid Build Coastguard Worker### abort\_on\_error 493*8d67ca89SAndroid Build Coastguard WorkerWhen malloc debug detects an error, abort after sending the error 494*8d67ca89SAndroid Build Coastguard Workerlog message. 495*8d67ca89SAndroid Build Coastguard Worker 496*8d67ca89SAndroid Build Coastguard Worker**NOTE**: If leak\_track is enabled, no abort occurs if leaks have been 497*8d67ca89SAndroid Build Coastguard Workerdetected when the process is exiting. 498*8d67ca89SAndroid Build Coastguard Worker 499*8d67ca89SAndroid Build Coastguard Worker### verbose 500*8d67ca89SAndroid Build Coastguard WorkerAs of Android Q, all info messages will be turned off by default. For example, 501*8d67ca89SAndroid Build Coastguard Workerin Android P and older, enabling malloc debug would result in this message 502*8d67ca89SAndroid Build Coastguard Workerin the log: 503*8d67ca89SAndroid Build Coastguard Worker 504*8d67ca89SAndroid Build Coastguard Worker 08-16 15:54:16.060 26947 26947 I libc : /system/bin/app_process64: malloc debug enabled 505*8d67ca89SAndroid Build Coastguard Worker 506*8d67ca89SAndroid Build Coastguard WorkerIn android Q, this message will not be displayed because these info messages 507*8d67ca89SAndroid Build Coastguard Workerslow down process start up. However, if you want to re-enable these messages, 508*8d67ca89SAndroid Build Coastguard Workeradd the verbose option. All of the "Run XXX" messages are also silenced unless 509*8d67ca89SAndroid Build Coastguard Workerthe verbose option is specified. This is an example of the type 510*8d67ca89SAndroid Build Coastguard Workerof messages that are no longer displayed: 511*8d67ca89SAndroid Build Coastguard Worker 512*8d67ca89SAndroid Build Coastguard Worker 09-10 01:03:50.070 557 557 I malloc_debug: /system/bin/audioserver: Run: 'kill -47 557' to dump the backtrace. 513*8d67ca89SAndroid Build Coastguard Worker 514*8d67ca89SAndroid Build Coastguard WorkerAdditional Errors 515*8d67ca89SAndroid Build Coastguard Worker----------------- 516*8d67ca89SAndroid Build Coastguard WorkerThere are a few other error messages that might appear in the log. 517*8d67ca89SAndroid Build Coastguard Worker 518*8d67ca89SAndroid Build Coastguard Worker### Use After Free 519*8d67ca89SAndroid Build Coastguard Worker 04-15 12:00:31.304 7412 7412 E malloc_debug: +++ ALLOCATION 0x12345678 USED AFTER FREE (free) 520*8d67ca89SAndroid Build Coastguard Worker 04-15 12:00:31.305 7412 7412 E malloc_debug: Backtrace of original free: 521*8d67ca89SAndroid Build Coastguard Worker 04-15 12:00:31.305 7412 7412 E malloc_debug: #00 pc 00029310 /system/lib/libc.so 522*8d67ca89SAndroid Build Coastguard Worker 04-15 12:00:31.305 7412 7412 E malloc_debug: #01 pc 00021438 /system/lib/libc.so (newlocale+160) 523*8d67ca89SAndroid Build Coastguard Worker 04-15 12:00:31.305 7412 7412 E malloc_debug: #02 pc 000a9e38 /system/lib/libc++.so 524*8d67ca89SAndroid Build Coastguard Worker 04-15 12:00:31.305 7412 7412 E malloc_debug: #03 pc 000a28a8 /system/lib/libc++.so 525*8d67ca89SAndroid Build Coastguard Worker 04-15 12:00:31.305 7412 7412 E malloc_debug: Backtrace at time of failure: 526*8d67ca89SAndroid Build Coastguard Worker 04-15 12:00:31.305 7412 7412 E malloc_debug: #00 pc 00029310 /system/lib/libc.so 527*8d67ca89SAndroid Build Coastguard Worker 04-15 12:00:31.305 7412 7412 E malloc_debug: #01 pc 00021438 /system/lib/libc.so (newlocale+160) 528*8d67ca89SAndroid Build Coastguard Worker 04-15 12:00:31.305 7412 7412 E malloc_debug: #02 pc 000a9e38 /system/lib/libc++.so 529*8d67ca89SAndroid Build Coastguard Worker 04-15 12:00:31.305 7412 7412 E malloc_debug: #03 pc 000a28a8 /system/lib/libc++.so 530*8d67ca89SAndroid Build Coastguard Worker 531*8d67ca89SAndroid Build Coastguard WorkerThis indicates that code is attempting to free an already freed pointer. The 532*8d67ca89SAndroid Build Coastguard Workername in parenthesis indicates that the application called the function 533*8d67ca89SAndroid Build Coastguard Worker*free* with the bad pointer. 534*8d67ca89SAndroid Build Coastguard Worker 535*8d67ca89SAndroid Build Coastguard WorkerFor example, this message: 536*8d67ca89SAndroid Build Coastguard Worker 537*8d67ca89SAndroid Build Coastguard Worker 04-15 12:00:31.304 7412 7412 E malloc_debug: +++ ALLOCATION 0x12345678 USED AFTER FREE (realloc) 538*8d67ca89SAndroid Build Coastguard Worker 539*8d67ca89SAndroid Build Coastguard WorkerWould indicate that the application called the *realloc* function 540*8d67ca89SAndroid Build Coastguard Workerwith an already freed pointer. 541*8d67ca89SAndroid Build Coastguard Worker 542*8d67ca89SAndroid Build Coastguard Worker### Invalid Tag 543*8d67ca89SAndroid Build Coastguard Worker 04-15 12:00:31.304 7412 7412 E malloc_debug: +++ ALLOCATION 0x12345678 HAS INVALID TAG 1ee7d000 (malloc_usable_size) 544*8d67ca89SAndroid Build Coastguard Worker 04-15 12:00:31.305 7412 7412 E malloc_debug: Backtrace at time of failure: 545*8d67ca89SAndroid Build Coastguard Worker 04-15 12:00:31.305 7412 7412 E malloc_debug: #00 pc 00029310 /system/lib/libc.so 546*8d67ca89SAndroid Build Coastguard Worker 04-15 12:00:31.305 7412 7412 E malloc_debug: #01 pc 00021438 /system/lib/libc.so (newlocale+160) 547*8d67ca89SAndroid Build Coastguard Worker 04-15 12:00:31.305 7412 7412 E malloc_debug: #02 pc 000a9e38 /system/lib/libc++.so 548*8d67ca89SAndroid Build Coastguard Worker 04-15 12:00:31.305 7412 7412 E malloc_debug: #03 pc 000a28a8 /system/lib/libc++.so 549*8d67ca89SAndroid Build Coastguard Worker 550*8d67ca89SAndroid Build Coastguard WorkerThis indicates that a function (malloc\_usable\_size) was called with 551*8d67ca89SAndroid Build Coastguard Workera pointer that is either not allocated memory, or that the memory of 552*8d67ca89SAndroid Build Coastguard Workerthe pointer has been corrupted. 553*8d67ca89SAndroid Build Coastguard Worker 554*8d67ca89SAndroid Build Coastguard WorkerAs with the other error message, the function in parenthesis is the 555*8d67ca89SAndroid Build Coastguard Workerfunction that was called with the bad pointer. 556*8d67ca89SAndroid Build Coastguard Worker 557*8d67ca89SAndroid Build Coastguard WorkerBacktrace Heap Dump Format 558*8d67ca89SAndroid Build Coastguard Worker========================== 559*8d67ca89SAndroid Build Coastguard Worker 560*8d67ca89SAndroid Build Coastguard WorkerThis section describes the format of the backtrace heap dump. This data is 561*8d67ca89SAndroid Build Coastguard Workergenerated by am dumpheap -n or, as of P, by the signal or on exit. 562*8d67ca89SAndroid Build Coastguard Worker 563*8d67ca89SAndroid Build Coastguard WorkerThe data has this header: 564*8d67ca89SAndroid Build Coastguard Worker 565*8d67ca89SAndroid Build Coastguard Worker Android Native Heap Dump v1.0 566*8d67ca89SAndroid Build Coastguard Worker 567*8d67ca89SAndroid Build Coastguard Worker Total memory: XXXX 568*8d67ca89SAndroid Build Coastguard Worker Allocation records: YYYY 569*8d67ca89SAndroid Build Coastguard Worker Backtrace size: ZZZZ 570*8d67ca89SAndroid Build Coastguard Worker 571*8d67ca89SAndroid Build Coastguard WorkerTotal memory is the total of all of the currently live allocations. 572*8d67ca89SAndroid Build Coastguard WorkerAllocation records is the total number of allocation records. 573*8d67ca89SAndroid Build Coastguard WorkerBacktrace size is the maximum number of backtrace frames that can be present. 574*8d67ca89SAndroid Build Coastguard Worker 575*8d67ca89SAndroid Build Coastguard WorkerFollowing this header are two different sections, the first section is the 576*8d67ca89SAndroid Build Coastguard Workerallocation records, the second section is the map data. 577*8d67ca89SAndroid Build Coastguard Worker 578*8d67ca89SAndroid Build Coastguard WorkerThe allocation record data has this format: 579*8d67ca89SAndroid Build Coastguard Worker 580*8d67ca89SAndroid Build Coastguard Worker z ZYGOTE_CHILD_ALLOC sz ALLOCATION_SIZE num NUM_ALLOCATIONS bt FRAMES 581*8d67ca89SAndroid Build Coastguard Worker 582*8d67ca89SAndroid Build Coastguard WorkerZYGOTE\_CHILD\_ALLOC is either 0 or 1. 0 means this was allocated by the 583*8d67ca89SAndroid Build Coastguard Workerzygote process or in a process not spawned from the zygote. 1 means this 584*8d67ca89SAndroid Build Coastguard Workerwas allocated by an application after it forked off from the zygote process. 585*8d67ca89SAndroid Build Coastguard Worker 586*8d67ca89SAndroid Build Coastguard WorkerALLOCATION\_SIZE is the size of the allocation. 587*8d67ca89SAndroid Build Coastguard WorkerNUM\_ALLOCATIONS is the number of allocations that have this size and have the 588*8d67ca89SAndroid Build Coastguard Workersame backtrace. 589*8d67ca89SAndroid Build Coastguard WorkerFRAMES is a list of instruction pointers that represent the backtrace of the 590*8d67ca89SAndroid Build Coastguard Workerallocation. 591*8d67ca89SAndroid Build Coastguard Worker 592*8d67ca89SAndroid Build Coastguard WorkerExample: 593*8d67ca89SAndroid Build Coastguard Worker 594*8d67ca89SAndroid Build Coastguard Worker z 0 sz 400 num 1 bt 0000a230 0000b500 595*8d67ca89SAndroid Build Coastguard Worker z 1 sz 500 num 3 bt 0000b000 0000c000 596*8d67ca89SAndroid Build Coastguard Worker 597*8d67ca89SAndroid Build Coastguard WorkerThe first allocation record was created by the zygote of size 400 only one 598*8d67ca89SAndroid Build Coastguard Workerwith this backtrace/size and a backtrace of 0xa230, 0xb500. 599*8d67ca89SAndroid Build Coastguard WorkerThe second allocation record was create by an application spawned from the 600*8d67ca89SAndroid Build Coastguard Workerzygote of size 500, where there are three of these allocation with the same 601*8d67ca89SAndroid Build Coastguard Workerbacktrace/size and a backtrace of 0xb000, 0xc000. 602*8d67ca89SAndroid Build Coastguard Worker 603*8d67ca89SAndroid Build Coastguard WorkerThe final section is the map data for the process: 604*8d67ca89SAndroid Build Coastguard Worker 605*8d67ca89SAndroid Build Coastguard Worker MAPS 606*8d67ca89SAndroid Build Coastguard Worker 7fe9181000-7fe91a2000 rw-p 00000000 00:00 0 /system/lib/libc.so 607*8d67ca89SAndroid Build Coastguard Worker . 608*8d67ca89SAndroid Build Coastguard Worker . 609*8d67ca89SAndroid Build Coastguard Worker . 610*8d67ca89SAndroid Build Coastguard Worker END 611*8d67ca89SAndroid Build Coastguard Worker 612*8d67ca89SAndroid Build Coastguard WorkerThe map data is simply the output of /proc/PID/maps. This data can be used to 613*8d67ca89SAndroid Build Coastguard Workerdecode the frames in the backtraces. 614*8d67ca89SAndroid Build Coastguard Worker 615*8d67ca89SAndroid Build Coastguard WorkerThere are now multiple versions of the file: 616*8d67ca89SAndroid Build Coastguard Worker 617*8d67ca89SAndroid Build Coastguard WorkerAndroid P produces version v1.1 of the heap dump. 618*8d67ca89SAndroid Build Coastguard Worker 619*8d67ca89SAndroid Build Coastguard Worker Android Native Heap Dump v1.1 620*8d67ca89SAndroid Build Coastguard Worker 621*8d67ca89SAndroid Build Coastguard WorkerThe only difference between v1.0 and v1.1 is that the NUM\_ALLOCATIONS 622*8d67ca89SAndroid Build Coastguard Workervalue is always accurate in v1.1. A previous version of malloc debug set 623*8d67ca89SAndroid Build Coastguard WorkerNUM\_ALLOCATIONS to an incorrect value. For heap dump v1.0, the 624*8d67ca89SAndroid Build Coastguard WorkerNUM\_ALLOCATIONS value should be treated as always 1 no matter what is 625*8d67ca89SAndroid Build Coastguard Workeractually present. 626*8d67ca89SAndroid Build Coastguard Worker 627*8d67ca89SAndroid Build Coastguard WorkerAndroid Q introduces v1.2 of the heap dump. The new header looks like this: 628*8d67ca89SAndroid Build Coastguard Worker 629*8d67ca89SAndroid Build Coastguard Worker Android Native Heap Dump v1.2 630*8d67ca89SAndroid Build Coastguard Worker 631*8d67ca89SAndroid Build Coastguard Worker Build fingerprint: 'google/taimen/taimen:8.1.0/OPM2.171026.006.C1/4769658:user/release-keys' 632*8d67ca89SAndroid Build Coastguard Worker 633*8d67ca89SAndroid Build Coastguard WorkerThe new line fingerprint line is the contents of the ro.build.fingerprint 634*8d67ca89SAndroid Build Coastguard Workerproperty. 635*8d67ca89SAndroid Build Coastguard Worker 636*8d67ca89SAndroid Build Coastguard WorkerThe new version no longer 0 pads the backtrace addresses. In v1.0/v1.1: 637*8d67ca89SAndroid Build Coastguard Worker 638*8d67ca89SAndroid Build Coastguard Worker z 0 sz 400 num 1 bt 0000a230 0000b500 639*8d67ca89SAndroid Build Coastguard Worker 640*8d67ca89SAndroid Build Coastguard WorkerWhile v1.2: 641*8d67ca89SAndroid Build Coastguard Worker 642*8d67ca89SAndroid Build Coastguard Worker z 0 sz 400 num 1 bt a230 b500 643*8d67ca89SAndroid Build Coastguard Worker 644*8d67ca89SAndroid Build Coastguard WorkerIn addition, when the new option backtrace\_full is used, another line will 645*8d67ca89SAndroid Build Coastguard Workerbe added to every backtrace line. The line will be: 646*8d67ca89SAndroid Build Coastguard Worker 647*8d67ca89SAndroid Build Coastguard Worker bt_info {"MAP_NAME" RELATIVE_TO_MAP_PC "FUNCTION_NAME" FUNCTION_OFFSET} ... 648*8d67ca89SAndroid Build Coastguard Worker 649*8d67ca89SAndroid Build Coastguard WorkerFor each backtrace pc, there will be one element in braces. 650*8d67ca89SAndroid Build Coastguard Worker 651*8d67ca89SAndroid Build Coastguard WorkerMAP\_NAME is the name of the map in which the backtrace pc exists. If there is 652*8d67ca89SAndroid Build Coastguard Workerno valid map name, this will be empty. 653*8d67ca89SAndroid Build Coastguard WorkerRELATIVE\_TO\_MAP\_PC is the hexadecimal value of the relative pc to the map. 654*8d67ca89SAndroid Build Coastguard WorkerFUNCTION\_NAME the name of the function for this pc. If there is no valid 655*8d67ca89SAndroid Build Coastguard Workerfunction name, then it will be empty. 656*8d67ca89SAndroid Build Coastguard WorkerFUNCTION\_OFFSET the hexadecimal offset from the beginning of the function. If 657*8d67ca89SAndroid Build Coastguard Workerthe FUNCTION\_NAME is empty, then this value will always be zero. 658*8d67ca89SAndroid Build Coastguard Worker 659*8d67ca89SAndroid Build Coastguard WorkerAn example of this new format: 660*8d67ca89SAndroid Build Coastguard Worker 661*8d67ca89SAndroid Build Coastguard Worker z 0 sz 400 num 1 bt a2a0 b510 662*8d67ca89SAndroid Build Coastguard Worker bt_info {"/system/libc.so" 2a0 "abort" 24} {"/system/libutils.so" 510 "" 0} 663*8d67ca89SAndroid Build Coastguard Worker 664*8d67ca89SAndroid Build Coastguard WorkerIn this example, the first backtrace frame has a pc of 0xa2a0 and is in the 665*8d67ca89SAndroid Build Coastguard Workermap named /system/libc.so which starts at 0xa000. The relative pc is 0x2a0, 666*8d67ca89SAndroid Build Coastguard Workerand it is in the function abort + 0x24. 667*8d67ca89SAndroid Build Coastguard WorkerThe second backtrace frame has a pc of 0xb510 and is in the map named 668*8d67ca89SAndroid Build Coastguard Worker/system/libutils.so which starts at 0xb000. The relative pc is 0x510 and 669*8d67ca89SAndroid Build Coastguard Workerit is in an unknown function. 670*8d67ca89SAndroid Build Coastguard Worker 671*8d67ca89SAndroid Build Coastguard WorkerExamples 672*8d67ca89SAndroid Build Coastguard Worker======== 673*8d67ca89SAndroid Build Coastguard Worker 674*8d67ca89SAndroid Build Coastguard Worker### For platform developers 675*8d67ca89SAndroid Build Coastguard Worker 676*8d67ca89SAndroid Build Coastguard WorkerEnable backtrace tracking of all allocation for all processes: 677*8d67ca89SAndroid Build Coastguard Worker 678*8d67ca89SAndroid Build Coastguard Worker adb shell stop 679*8d67ca89SAndroid Build Coastguard Worker adb shell setprop libc.debug.malloc.options backtrace 680*8d67ca89SAndroid Build Coastguard Worker adb shell start 681*8d67ca89SAndroid Build Coastguard Worker 682*8d67ca89SAndroid Build Coastguard WorkerEnable backtrace tracking for a specific process (ls): 683*8d67ca89SAndroid Build Coastguard Worker 684*8d67ca89SAndroid Build Coastguard Worker adb shell setprop libc.debug.malloc.options backtrace 685*8d67ca89SAndroid Build Coastguard Worker adb shell setprop libc.debug.malloc.program ls 686*8d67ca89SAndroid Build Coastguard Worker adb shell ls 687*8d67ca89SAndroid Build Coastguard Worker 688*8d67ca89SAndroid Build Coastguard WorkerEnable backtrace tracking for the zygote and zygote based processes: 689*8d67ca89SAndroid Build Coastguard Worker 690*8d67ca89SAndroid Build Coastguard Worker adb shell stop 691*8d67ca89SAndroid Build Coastguard Worker adb shell setprop libc.debug.malloc.program app_process 692*8d67ca89SAndroid Build Coastguard Worker adb shell setprop libc.debug.malloc.options backtrace 693*8d67ca89SAndroid Build Coastguard Worker adb shell start 694*8d67ca89SAndroid Build Coastguard Worker 695*8d67ca89SAndroid Build Coastguard WorkerEnable multiple options (backtrace and guard): 696*8d67ca89SAndroid Build Coastguard Worker 697*8d67ca89SAndroid Build Coastguard Worker adb shell stop 698*8d67ca89SAndroid Build Coastguard Worker adb shell setprop libc.debug.malloc.options "\"backtrace guard\"" 699*8d67ca89SAndroid Build Coastguard Worker adb shell start 700*8d67ca89SAndroid Build Coastguard Worker 701*8d67ca89SAndroid Build Coastguard WorkerNote: The two levels of quoting in the adb shell command is necessary. 702*8d67ca89SAndroid Build Coastguard WorkerThe outer layer of quoting is for the shell on the host, to ensure that the 703*8d67ca89SAndroid Build Coastguard Workerinner layer of quoting is sent to the device, to make 'backtrace guard' 704*8d67ca89SAndroid Build Coastguard Workera single argument. 705*8d67ca89SAndroid Build Coastguard Worker 706*8d67ca89SAndroid Build Coastguard WorkerEnable malloc debug using an environment variable (pre-O Android release): 707*8d67ca89SAndroid Build Coastguard Worker 708*8d67ca89SAndroid Build Coastguard Worker adb shell 709*8d67ca89SAndroid Build Coastguard Worker # setprop libc.debug.malloc.env_enabled 1 710*8d67ca89SAndroid Build Coastguard Worker # setprop libc.debug.malloc.options backtrace 711*8d67ca89SAndroid Build Coastguard Worker # export LIBC_DEBUG_MALLOC_ENABLE=1 712*8d67ca89SAndroid Build Coastguard Worker # ls 713*8d67ca89SAndroid Build Coastguard Worker 714*8d67ca89SAndroid Build Coastguard WorkerEnable malloc debug using an environment variable (Android O or later): 715*8d67ca89SAndroid Build Coastguard Worker 716*8d67ca89SAndroid Build Coastguard Worker adb shell 717*8d67ca89SAndroid Build Coastguard Worker # export LIBC_DEBUG_MALLOC_OPTIONS=backtrace 718*8d67ca89SAndroid Build Coastguard Worker # ls 719*8d67ca89SAndroid Build Coastguard Worker 720*8d67ca89SAndroid Build Coastguard WorkerAny process spawned from this shell will run with malloc debug enabled 721*8d67ca89SAndroid Build Coastguard Workerusing the backtrace option. 722*8d67ca89SAndroid Build Coastguard Worker 723*8d67ca89SAndroid Build Coastguard Worker adb shell stop 724*8d67ca89SAndroid Build Coastguard Worker adb shell setprop libc.debug.malloc.options backtrace 725*8d67ca89SAndroid Build Coastguard Worker adb shell start 726*8d67ca89SAndroid Build Coastguard Worker adb shell am dumpheap -n <PID_TO_DUMP> /data/local/tmp/heap.txt 727*8d67ca89SAndroid Build Coastguard Worker 728*8d67ca89SAndroid Build Coastguard WorkerIt is possible to use the backtrace\_enable\_on\_signal option as well, 729*8d67ca89SAndroid Build Coastguard Workerbut, obviously, it must be enabled through the signal before the file will 730*8d67ca89SAndroid Build Coastguard Workercontain any data. 731*8d67ca89SAndroid Build Coastguard Worker 732*8d67ca89SAndroid Build Coastguard Worker### For app developers 733*8d67ca89SAndroid Build Coastguard Worker 734*8d67ca89SAndroid Build Coastguard WorkerApp developers should check the NDK documentation about 735*8d67ca89SAndroid Build Coastguard Worker[wrap.sh](https://developer.android.com/ndk/guides/wrap-script.html) 736*8d67ca89SAndroid Build Coastguard Workerfor the best way to use malloc debug in Android O or later on non-rooted 737*8d67ca89SAndroid Build Coastguard Workerdevices. 738*8d67ca89SAndroid Build Coastguard Worker 739*8d67ca89SAndroid Build Coastguard Worker**NOTE**: Android 12 introduced a bug that can cause the wrap.\<APP\> property to 740*8d67ca89SAndroid Build Coastguard Workerno longer work. Use the commands below so that the wrap.\<APP\> instructions will work: 741*8d67ca89SAndroid Build Coastguard Worker 742*8d67ca89SAndroid Build Coastguard Worker adb shell setprop dalvik.vm.force-java-zygote-fork-loop true 743*8d67ca89SAndroid Build Coastguard Worker adb shell stop 744*8d67ca89SAndroid Build Coastguard Worker adb shell start 745*8d67ca89SAndroid Build Coastguard Worker 746*8d67ca89SAndroid Build Coastguard WorkerIf you do have a rooted device, you can enable malloc debug for a specific 747*8d67ca89SAndroid Build Coastguard Workerprogram/application (Android O or later): 748*8d67ca89SAndroid Build Coastguard Worker 749*8d67ca89SAndroid Build Coastguard Worker adb shell setprop wrap.<APP> '"LIBC_DEBUG_MALLOC_OPTIONS=backtrace logwrapper"' 750*8d67ca89SAndroid Build Coastguard Worker 751*8d67ca89SAndroid Build Coastguard WorkerIf you need to enable multiple options using this method, then you can set 752*8d67ca89SAndroid Build Coastguard Workerthem like so: 753*8d67ca89SAndroid Build Coastguard Worker 754*8d67ca89SAndroid Build Coastguard Worker adb shell setprop wrap.<APP> '"LIBC_DEBUG_MALLOC_OPTIONS=backtrace\ leak_track\ fill logwrapper"' 755*8d67ca89SAndroid Build Coastguard Worker 756*8d67ca89SAndroid Build Coastguard WorkerFor example, to enable malloc debug for the google search box (Android O or later): 757*8d67ca89SAndroid Build Coastguard Worker 758*8d67ca89SAndroid Build Coastguard Worker adb shell setprop wrap.com.google.android.googlequicksearchbox '"LIBC_DEBUG_MALLOC_OPTIONS=backtrace logwrapper"' 759*8d67ca89SAndroid Build Coastguard Worker adb shell am force-stop com.google.android.googlequicksearchbox 760*8d67ca89SAndroid Build Coastguard Worker 761*8d67ca89SAndroid Build Coastguard WorkerIf you are setting multiple options and the app does not appear to start 762*8d67ca89SAndroid Build Coastguard Workerproperly, check the logcat looking for this message 763*8d67ca89SAndroid Build Coastguard Worker(`adb logcat -d | grep "malloc debug"`): 764*8d67ca89SAndroid Build Coastguard Worker 765*8d67ca89SAndroid Build Coastguard Worker 08-16 15:54:16.060 26947 26947 I libc : /system/bin/app_process64: malloc debug enabled 766*8d67ca89SAndroid Build Coastguard Worker 767*8d67ca89SAndroid Build Coastguard WorkerIf you do not see this message, then the wrap property was not set correctly. 768*8d67ca89SAndroid Build Coastguard WorkerRun: 769*8d67ca89SAndroid Build Coastguard Worker 770*8d67ca89SAndroid Build Coastguard Worker adb shell getprop | grep wrap 771*8d67ca89SAndroid Build Coastguard Worker 772*8d67ca89SAndroid Build Coastguard WorkerAnd verify that any spaces are properly escaped. 773*8d67ca89SAndroid Build Coastguard Worker 774*8d67ca89SAndroid Build Coastguard WorkerNOTE: On pre-O versions of the Android OS, property names had a length limit 775*8d67ca89SAndroid Build Coastguard Workerof 32. This meant that to create a wrap property with the name of the app, it 776*8d67ca89SAndroid Build Coastguard Workerwas necessary to truncate the name to fit. On O, property names can be 777*8d67ca89SAndroid Build Coastguard Workeran order of magnitude larger, so there should be no need to truncate the name 778*8d67ca89SAndroid Build Coastguard Workerat all. 779*8d67ca89SAndroid Build Coastguard Worker 780*8d67ca89SAndroid Build Coastguard WorkerTo detect leaks while an app is running: 781*8d67ca89SAndroid Build Coastguard Worker 782*8d67ca89SAndroid Build Coastguard Worker adb shell dumpsys meminfo --unreachable <PID_OF_APP> 783*8d67ca89SAndroid Build Coastguard Worker 784*8d67ca89SAndroid Build Coastguard WorkerWithout also enabling malloc debug, this command will only tell 785*8d67ca89SAndroid Build Coastguard Workeryou whether it can detect leaked memory, not where those leaks are 786*8d67ca89SAndroid Build Coastguard Workeroccurring. If you enable malloc debug with the backtrace option for your 787*8d67ca89SAndroid Build Coastguard Workerapp before running the dumpsys command, you'll get backtraces showing 788*8d67ca89SAndroid Build Coastguard Workerwhere the memory was allocated. 789*8d67ca89SAndroid Build Coastguard Worker 790*8d67ca89SAndroid Build Coastguard WorkerFor backtraces from your app to be useful, you'll want to keep the 791*8d67ca89SAndroid Build Coastguard Workersymbols in your app's shared libraries rather than stripping them. That 792*8d67ca89SAndroid Build Coastguard Workerway you'll see the location of the leak directly without having to use 793*8d67ca89SAndroid Build Coastguard Workersomething like the <code>ndk-stack</code> tool. 794