How to detect memory leaks in native code?

1,841 views
Skip to first unread message

Harjot Singh

unread,
May 12, 2017, 10:09:56 AM5/12/17
to android-ndk
Hi

I have been trying to find a way to detect memory leaks and track memory allocations on the C++ side of code, but didn't find anything useful.

I found the DDMS solution to enable the "native heap" tab in it, but that is no longer working post Android 18. I tried downloading the old tools and running the old DDMS with the current SDK but that doesn't seem to work.

I will be really helpful is someone can help me out!

I seriously don't know why doesn't such a trivial problem have a solution directly in Android Studio!! Xcode on the other hand is going way head as compared to Android Studio, this is a poor state of affairs!!

Regards
Harjot Singh


Dan Albert

unread,
May 12, 2017, 4:05:06 PM5/12/17
to android-ndk
For anyone else landing here, this was also asked on Stack Overflow. I've left an answer pointing to ASAN: http://stackoverflow.com/a/43944877/632035

--
You received this message because you are subscribed to the Google Groups "android-ndk" group.
To unsubscribe from this group and stop receiving emails from it, send an email to android-ndk+unsubscribe@googlegroups.com.
To post to this group, send email to andro...@googlegroups.com.
Visit this group at https://groups.google.com/group/android-ndk.
To view this discussion on the web visit https://groups.google.com/d/msgid/android-ndk/37d9c2fc-88f6-4159-860c-d34c2298cdf0%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

kang joni

unread,
May 13, 2017, 8:58:06 PM5/13/17
to android-ndk
@Dan is there any reason why jelly bean is unsupported for address sanitizer use?

Dan Albert

unread,
May 13, 2017, 11:31:38 PM5/13/17
to android-ndk
I don't know for sure, but I'm pretty sure this had to do with the fact that the way Android was build made it impossible for ASAN to function. ASAN needs to be able to hook libc functions like malloc/free, and that was not possible on Android until L because prior to that everything was linked -Bsymbolic (which resolves all relocations at link time, inhibiting pre-emption). ASAN worked on K despite the fact that everything was still linked in this manner because support for pre-empting those functions was specifically added to libc in that release.

On Sat, May 13, 2017 at 2:42 AM, kang joni <kangj...@gmail.com> wrote:
@Dan is there any reason why jelly bean is unsupported for address sanitizer use?
--
You received this message because you are subscribed to the Google Groups "android-ndk" group.
To unsubscribe from this group and stop receiving emails from it, send an email to android-ndk+unsubscribe@googlegroups.com.
To post to this group, send email to andro...@googlegroups.com.
Visit this group at https://groups.google.com/group/android-ndk.

kang joni

unread,
May 14, 2017, 2:47:44 PM5/14/17
to andro...@googlegroups.com
So the conclusion is that ASAN must have to re-implement some of libc
function that is being used by ASAN itself on android version before
kitkat, isn't?

On 5/14/17, 'Dan Albert' via android-ndk <andro...@googlegroups.com> wrote:
> I don't know for sure, but I'm pretty sure this had to do with the fact
> that the way Android was build made it impossible for ASAN to function.
> ASAN needs to be able to hook libc functions like malloc/free, and that was
> not possible on Android until L because prior to that everything was linked
> -Bsymbolic (which resolves all relocations at link time, inhibiting
> pre-emption). ASAN worked on K despite the fact that everything was still
> linked in this manner because support for pre-empting those functions was
> specifically added to libc in that release.
>
> On Sat, May 13, 2017 at 2:42 AM, kang joni <kangj...@gmail.com> wrote:
>
>> @Dan is there any reason why jelly bean is unsupported for address
>> sanitizer use?
>>
>> --
>> You received this message because you are subscribed to the Google Groups
>> "android-ndk" group.
>> To unsubscribe from this group and stop receiving emails from it, send an
>> email to android-ndk...@googlegroups.com.
>> To post to this group, send email to andro...@googlegroups.com.
>> Visit this group at https://groups.google.com/group/android-ndk.
>> To view this discussion on the web visit https://groups.google.com/d/
>> msgid/android-ndk/142203a4-e55e-4a14-abe6-e114179ca7d0%40googlegroups.com.
>> For more options, visit https://groups.google.com/d/optout.
>>
>
> --
> You received this message because you are subscribed to a topic in the
> Google Groups "android-ndk" group.
> To unsubscribe from this topic, visit
> https://groups.google.com/d/topic/android-ndk/jAMgktML6Vs/unsubscribe.
> To unsubscribe from this group and all its topics, send an email to
> android-ndk...@googlegroups.com.
> To post to this group, send email to andro...@googlegroups.com.
> Visit this group at https://groups.google.com/group/android-ndk.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/android-ndk/CAFVaGhtqy%3DdjP%2BMjsfTNjpHvATTb4bUFaHz3d7R0zsZuX7MfOg%40mail.gmail.com.
Reply all
Reply to author
Forward
0 new messages