Malloc debug on Android Nougat doesnt work for my Native code
<p>I am trying to find memory leaks and corruptions in my native code, which is part of a sample java app. Since the procedure for using malloc debug has been updated from Nougat onwards (ref: <a href="https://android.googlesource.com/platform/bionic/+/master/libc/malloc_debug/README.md" rel="nofollow noreferrer">Malloc Debug for Android N</a>), I have followed the steps in that page to set the options of my interest.</p>

<p>Fortunately, I was able to get the mem corruption detection work (by use of guard option) for a simple buffer overflow in my native code. But, whatever option I use, I couldn't get the leaks detected.</p>

<p>I tried these options:</p>

<pre><code>adb shell setprop libc.debug.malloc.options backtrace

adb shell setprop libc.debug.malloc.options leak_track
</code></pre>

<p>I also tried a combination of both options. I didnt see any mallocs or leaks present in my code being captured in logcat. In fact, for most devices I see that device is stuck in bootup when 'backtrace' option is set.</p>

<p>However, what I see is in the logs, is apparently false-positives for leaks in lot of other system programs:</p>

<pre><code>12-16 13:05:51.908  8396  8396 E malloc_debug: +++ chmod leaked block of size 152 at 0x7f7de4b0e0 (leak 1 of 19)
...
12-16 13:05:52.156  8423  8423 E malloc_debug: +++ chown leaked block of size 152 at 0x7f8384b0e0 (leak 1 of 26)
...
12-16 13:05:56.533  8845  8845 E malloc_debug: +++ getprop leaked block of size 152 at 0x7fb684b0e0 (leak 1 of 17)
...
12-16 13:07:24.036 12393 12393 E malloc_debug: +++ /system/bin/dex2oat leaked block of size 131072 at 0xeb22c010 (leak 1 of 2452)
...
12-16 13:07:49.192 13734 13734 E malloc_debug: +++ logcat leaked block of size 5176 at 0x7f8dc5f020 (leak 1 of 21)
</code></pre>

<p>So, I have two questions in this context:</p>

<ol>
<li>Does my apk need to be in a specific location for backtrace/leak_track to work? Was it ever tested for apks before, at least on N?</li>
<li>Do I need to set any other option for leak detection to work?</li>
</ol>

<p>It looks like Malloc debug on Nougat is not explored much, so I didnt see any results on Google for any known issues or restrictions.</p>

<p>More details on my setup:<br>
 - Android Nougat 7.0<br>
 - 64 bit chipset<br>
 - Java sample app, with native code as shared lib</p>