malloc causes a crash

1,095 views
Skip to first unread message

ezmora

unread,
May 24, 2012, 9:16:52 AM5/24/12
to android-ndk
I face intermittent crashes in my native code.
Debugging the stack trace, I saw that it's in fact the call to
'malloc' that caused the crash.

1. Is there a way to keep track of total memory usage? (i.e.,
situations where we're running on low memory)
2. Is it possible that there’s a bug in android’s implementation of
malloc?
3. When can malloc crash (i.e, if the size passed to it is too big, or
negative)?

Is mcheck supported by the NDK?
Any other ideas how to proceed?

Eyal

Pablo Márquez

unread,
May 24, 2012, 9:28:34 AM5/24/12
to andro...@googlegroups.com
I would suggest implementing your own version of the allocators, then in your implementation you can track every allocation as you please.

I believe it's unlikely that there is a bug in Bionic's malloc, the problem is probably that your code is corrupting the memory and this makes malloc crash

Cheers,



--
You received this message because you are subscribed to the Google Groups "android-ndk" group.
To post to this group, send email to andro...@googlegroups.com.
To unsubscribe from this group, send email to android-ndk...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/android-ndk?hl=en.




--
....:::::: ^__^ ::::::....

David Turner

unread,
May 24, 2012, 9:49:04 AM5/24/12
to andro...@googlegroups.com
On Thu, May 24, 2012 at 3:16 PM, ezmora <eyal...@gmail.com> wrote:
I face intermittent crashes in my native code.
Debugging the stack trace, I saw that it's in fact the call to
'malloc' that caused the crash.

1. Is there a way to keep track of total memory usage? (i.e.,
situations where we're running on low memory)

Not really, "low on memory" is a very dynamic condition on Android because the system will make room for your application by shutting down other processes.
 
2. Is it possible that there’s a bug in android’s implementation of
malloc?

Very very unlikely (see below).
 
3. When can malloc crash (i.e, if the size passed to it is too big, or
negative)?


malloc will typically crash when it detects that the heap has been corrupted (due to a buggy program).
Actually, if the fault address is "0xdeadbaad", that's a special name to indicate that this exactly happened.

The root cause of the problem could be anywhere though, in your own code.
 
Is mcheck supported by the NDK?
Any other ideas how to proceed?

Eyal
Reply all
Reply to author
Forward
0 new messages