Crash reason (Java-JNI-Clang C API)?

i’m developing android app that uses Clang via C API (libclang) for ARM. I’ve wrote wrapper toinvoke clang_..() functions and map data between Java<->native code. So the app is working for few times and then crashing. It’s interacting with native code from java background thread (if that helps).

My idea about what’s wrong is:

  1. i’m trying to delete already deleted pointer
  2. there is a memory leak in my code/clang and heap is fully allocated
  3. concurrency issue

Any thoughts are highly appreciated:

Another crash (probable another reason) but with stacktrace:

12-11 00:10:38.106: INFO/DEBUG(166): r0 00000027 r1 deadbaad r2 4024cb0c r3 00000000
12-11 00:10:38.106: INFO/DEBUG(166): r4 00000000 r5 7e7a82bc r6 00000002 r7 00000002
12-11 00:10:38.106: INFO/DEBUG(166): r8 00000030 r9 7d3c0590 sl 7d3aae24 fp 40253a6c
12-11 00:10:38.106: INFO/DEBUG(166): ip 00004000 sp 7e7a82b8 lr 4021ec89 pc 4021b32a cpsr 60000030
12-11 00:10:38.106: INFO/DEBUG(166): d0 20656c6966206e69 d1 646564756c636e69
12-11 00:10:38.106: INFO/DEBUG(166): d2 6f63206d6f726620 d3 645f6574656c706d
12-11 00:10:38.106: INFO/DEBUG(166): d4 000002db000002c9 d5 000002ed000002ec
12-11 00:10:38.106: INFO/DEBUG(166): d6 000003ae0000039c d7 000003d4000003c1
12-11 00:10:38.106: INFO/DEBUG(166): d8 4418800000000262 d9 4434000043898000
12-11 00:10:38.106: INFO/DEBUG(166): d10 0000000042c00000 d11 0000000000000000
12-11 00:10:38.106: INFO/DEBUG(166): d12 0000000000000000 d13 0000000000000000
12-11 00:10:38.106: INFO/DEBUG(166): d14 0000000000000000 d15 0000000000000000
12-11 00:10:38.106: INFO/DEBUG(166): d16 6769736e75202c2a d17 29746e692064656e
12-11 00:10:38.106: INFO/DEBUG(166): d18 6c63206e6f697461 d19 78654c3a3a676e61
12-11 00:10:38.106: INFO/DEBUG(166): d20 537465673a3a7265 d21 636f4c656372756f
12-11 00:10:38.106: INFO/DEBUG(166): d22 6863286e6f697461 d23 74736e6f63207261
12-11 00:10:38.106: INFO/DEBUG(166): d24 0000000000000000 d25 0000000000000000
12-11 00:10:38.106: INFO/DEBUG(166): d26 0000000000000000 d27 0000000000000000
12-11 00:10:38.106: INFO/DEBUG(166): d28 0048004700460044 d29 004a0048004a0049
12-11 00:10:38.106: INFO/DEBUG(166): d30 0000000000000000 d31 0000000000000000
12-11 00:10:38.106: INFO/DEBUG(166): scr 28000013
12-11 00:10:38.126: INFO/DEBUG(166): backtrace:
12-11 00:10:38.126: INFO/DEBUG(166): #00 pc 0001832a /system/lib/libc.so
12-11 00:10:38.126: INFO/DEBUG(166): #01 pc 0000dc04 /system/lib/libc.so (abort+4)
12-11 00:10:38.126: INFO/DEBUG(166): #02 pc 0001f0df /system/lib/libc.so (__assert2+30)
12-11 00:10:38.126: INFO/DEBUG(166): #03 pc 0077c954 /data/data/name.antonsmirnov.android.arduinodroid/lib/libclang.so (clang::Lexer::getSourceLocation(char const*, unsigned int) const+76)
12-11 00:10:38.126: INFO/DEBUG(166): #04 pc 0077ca4c /data/data/name.antonsmirnov.android.arduinodroid/lib/libclang.so (clang::Lexer::FormTokenWithChars(clang::Token&, char const*, clang::tok::TokenKind)+100)
12-11 00:10:38.126: INFO/DEBUG(166): #05 pc 00781098 /data/data/name.antonsmirnov.android.arduinodroid/lib/libclang.so (clang::Lexer::LexTokenInternal(clang::Token&)+5616)
12-11 00:10:38.126: INFO/DEBUG(166): #06 pc 0015de68 /data/data/name.antonsmirnov.android.arduinodroid/lib/libclang.so (clang::Lexer::LexFromRawLexer(clang::Token&)+116)
12-11 00:10:38.126: INFO/DEBUG(166): #07 pc 00781d3c /data/data/name.antonsmirnov.android.arduinodroid/lib/libclang.so (clang::Lexer::getRawToken(clang::SourceLocation, clang::Token&, clang::SourceManager const&, clang::LangOptions const&)+220)
12-11 00:10:38.126: INFO/DEBUG(166): #08 pc 00781d9c /data/data/name.antonsmirnov.android.arduinodroid/lib/libclang.so (clang::Lexer::MeasureTokenLength(clang::SourceLocation, clang::SourceManager const&, clang::LangOptions const&)+36)
12-11 00:10:38.126: INFO/DEBUG(166): #09 pc 001d1824 /data/data/name.antonsmirnov.android.arduinodroid/lib/libclang.so (clang::DiagnosticRenderer::emitMacroExpansions(clang::SourceLocation, clang::DiagnosticsEngine::Level, llvm::ArrayRefclang::CharSourceRange, llvm::ArrayRefclang::FixItHint, clang::SourceManager const&, unsigned int&, unsigned int)+840)
12-11 00:10:38.126: INFO/DEBUG(166): #10 pc 001d13ec /data/data/name.antonsmirnov.android.arduinodroid/lib/libclang.so (clang::DiagnosticRenderer::emitDiagnostic(clang::SourceLocation, clang::DiagnosticsEngine::Level, llvm::StringRef, llvm::ArrayRefclang::CharSourceRange, llvm::ArrayRefclang::FixItHint, clang::SourceManager const*, llvm::PointerUnion<clang::Diagnostic const*, clang::StoredDiagnostic const*>)+1224)
12-11 00:10:38.126: INFO/DEBUG(166): #11 pc 001d1b20 /data/data/name.antonsmirnov.android.arduinodroid/lib/libclang.so (clang::DiagnosticRenderer::emitStoredDiagnostic(clang::StoredDiagnostic&)+304)
12-11 00:10:38.126: INFO/DEBUG(166): #12 pc 0017b1c8 /data/data/name.antonsmirnov.android.arduinodroid/lib/libclang.so (clang::cxdiag::lazyCreateDiags(CXTranslationUnitImpl*, bool)+248)
12-11 00:10:38.126: INFO/DEBUG(166): #13 pc 00009028 /data/data/name.antonsmirnov.android.arduinodroid/lib/libclang_wrapper.so (Java_name_antonsmirnov_clang_clang_1wrapper_getDiagnostics+72)
12-11 00:10:38.126: INFO/DEBUG(166): #14 pc 0001fb70 /system/lib/libdvm.so (dvmPlatformInvoke+112)
12-11 00:10:38.126: INFO/DEBUG(166): #15 pc 0004e8b9 /system/lib/libdvm.so (dvmCallJNIMethod(unsigned int const*, JValue*, Method const*, Thread*)+360)
12-11 00:10:38.126: INFO/DEBUG(166): #16 pc 00029020 /system/lib/libdvm.so
12-11 00:10:38.126: INFO/DEBUG(166): #17 pc 0002d7e8 /system/lib/libdvm.so (dvmInterpret(Thread*, Method const*, JValue*)+180)
12-11 00:10:38.126: INFO/DEBUG(166): #18 pc 0005fed5 /system/lib/libdvm.so (dvmCallMethodV(Thread*, Method const*, Object*, bool, JValue*, std::__va_list)+272)
12-11 00:10:38.126: INFO/DEBUG(166): #19 pc 0005feff /system/lib/libdvm.so (dvmCallMethod(Thread*, Method const*, Object*, JValue*, …)+20)
12-11 00:10:38.126: INFO/DEBUG(166): #20 pc 00055327 /system/lib/libdvm.so
12-11 00:10:38.126: INFO/DEBUG(166): #21 pc 00012e70 /system/lib/libc.so (__thread_entry+48)
12-11 00:10:38.126: INFO/DEBUG(166): #22 pc 000125c8 /system/lib/libc.so (pthread_create+172)
12-11 00:10:38.126: INFO/DEBUG(166): stack:
12-11 00:10:38.126: INFO/DEBUG(166): 7e7a8278 00000000
12-11 00:10:38.126: INFO/DEBUG(166): 7e7a827c c6c488f5
12-11 00:10:38.126: INFO/DEBUG(166): 7e7a8280 00001000
12-11 00:10:38.126: INFO/DEBUG(166): 7e7a8284 00000262
12-11 00:10:38.126: INFO/DEBUG(166): 7e7a8288 44188000 /dev/ashmem/dalvik-heap (deleted)
12-11 00:10:38.126: INFO/DEBUG(166): 7e7a828c 43898000 /dev/ashmem/dalvik-heap (deleted)
12-11 00:10:38.126: INFO/DEBUG(166): 7e7a8290 40247774 /system/lib/libc.so
12-11 00:10:38.126: INFO/DEBUG(166): 7e7a8294 4024cd10
12-11 00:10:38.126: INFO/DEBUG(166): 7e7a8298 00000000
12-11 00:10:38.126: INFO/DEBUG(166): 7e7a829c 4021ec89 /system/lib/libc.so (_fwalk+32)
12-11 00:10:38.126: INFO/DEBUG(166): 7e7a82a0 00000001
12-11 00:10:38.126: INFO/DEBUG(166): 7e7a82a4 7e7a82bc [stack:5011]
12-11 00:10:38.126: INFO/DEBUG(166): 7e7a82a8 00000002
12-11 00:10:38.126: INFO/DEBUG(166): 7e7a82ac 00000002
12-11 00:10:38.126: INFO/DEBUG(166): 7e7a82b0 df0027ad
12-11 00:10:38.126: INFO/DEBUG(166): 7e7a82b4 00000000
12-11 00:10:38.126: INFO/DEBUG(166): #00 7e7a82b8 75ff7ec2 /data/data/name.antonsmirnov.android.arduinodroid/lib/libclang.so
12-11 00:10:38.126: INFO/DEBUG(166): 7e7a82bc fffffbdf
12-11 00:10:38.126: INFO/DEBUG(166): 7e7a82c0 4023dbfc /system/lib/libc.so
12-11 00:10:38.126: INFO/DEBUG(166): 7e7a82c4 00000002
12-11 00:10:38.126: INFO/DEBUG(166): 7e7a82c8 00000002
12-11 00:10:38.126: INFO/DEBUG(166): 7e7a82cc 4021e1f5 /system/lib/libc.so (fprintf+16)
12-11 00:10:38.126: INFO/DEBUG(166): 7e7a82d0 40247718 /system/lib/libc.so
12-11 00:10:38.126: INFO/DEBUG(166): 7e7a82d4 75ff7ec2 /data/data/name.antonsmirnov.android.arduinodroid/lib/libclang.so
12-11 00:10:38.126: INFO/DEBUG(166): 7e7a82d8 4023dbfc /system/lib/libc.so
12-11 00:10:38.126: INFO/DEBUG(166): 7e7a82dc 40210c08 /system/lib/libc.so (__pthread_clone)
12-11 00:10:38.126: INFO/DEBUG(166): #01 7e7a82e0 7e7a82e0 [stack:5011]
12-11 00:10:38.126: INFO/DEBUG(166): 7e7a82e4 402220e3 /system/lib/libc.so (__assert2+34)
12-11 00:10:38.126: INFO/DEBUG(166): #02 7e7a82e8 0000042d
12-11 00:10:38.126: INFO/DEBUG(166): 7e7a82ec 75feace7 /data/data/name.antonsmirnov.android.arduinodroid/lib/libclang.so (clang::Lexer::getSourceLocation(char const*, unsigned int) const::PRETTY_FUNCTION)
12-11 00:10:38.126: INFO/DEBUG(166): 7e7a82f0 75feace7 /data/data/name.antonsmirnov.android.arduinodroid/lib/libclang.so (clang::Lexer::getSourceLocation(char const*, unsigned int) const::PRETTY_FUNCTION)
12-11 00:10:38.126: INFO/DEBUG(166): 7e7a82f4 75a7c958 /data/data/name.antonsmirnov.android.arduinodroid/lib/libclang.so (clang::Lexer::getSourceLocation(char const*, unsigned int) const+80)
12-11 00:10:38.136: INFO/DEBUG(166): memory near r2:
12-11 00:10:38.136: INFO/DEBUG(166): 4024caec 00000000 00000000 00000000 00000000 …
12-11 00:10:38.136: INFO/DEBUG(166): 4024cafc 00000000 00000000 00000000 00000000 …
12-11 00:10:38.136: INFO/DEBUG(166): 4024cb0c 00000001 00000000 00000000 00000000 …
12-11 00:10:38.136: INFO/DEBUG(166): 4024cb1c 00000000 00000000 00000000 00000000 …
12-11 00:10:38.136: INFO/DEBUG(166): 4024cb2c 00000000 00000000 00000000 00000000 …
12-11 00:10:38.136: INFO/DEBUG(166): memory near r5:
12-11 00:10:38.136: INFO/DEBUG(166): 7e7a829c 4021ec89 00000001 7e7a82bc 00000002 …!@…z~…
12-11 00:10:38.146: INFO/DEBUG(166): 7e7a82ac 00000002 df0027ad 00000000 75ff7ec2 …‘…~.u
12-11 00:10:38.146: INFO/DEBUG(166): 7e7a82bc fffffbdf 4023dbfc 00000002 00000002 …#@…
12-11 00:10:38.146: INFO/DEBUG(166): 7e7a82cc 4021e1f5 40247718 75ff7ec2 4023dbfc …!@.w$@.~.u…#@
12-11 00:10:38.146: INFO/DEBUG(166): 7e7a82dc 40210c08 7e7a82e0 402220e3 0000042d …!@…z~. "@-…
12-11 00:10:38.146: INFO/DEBUG(166): memory near r9:
12-11 00:10:38.146: INFO/DEBUG(166): 7d3c0570 7d39c9fc 7e020006 0003be14 00000001 …9}…~…
12-11 00:10:38.146: INFO/DEBUG(166): 7d3c0580 00000000 7e020015 0003be15 00000004 …~…
12-11 00:10:38.146: INFO/DEBUG(166): 7d3c0590 7e313d3c 7e000069 0003be19 00000001 <=1~i…~…
12-11 00:10:38.146: INFO/DEBUG(166): 7d3c05a0 00000000 7e000016 0003be1e 0000000d …~…
12-11 00:10:38.146: INFO/DEBUG(166): 7d3c05b0 7e1cbd10 7e0200a6 00000000 00000002 …~…~…
12-11 00:10:38.146: INFO/DEBUG(166): memory near sl:
12-11 00:10:38.146: INFO/DEBUG(166): 7d3aae04 7d3aae24 7d3aaf15 706d6f63 6574656c $.:}…:}complete
12-11 00:10:38.146: INFO/DEBUG(166): 7d3aae14 6d65645f 6e692e6f 70632e6f 67670070 _demo.ino.cpp.gg
12-11 00:10:38.146: INFO/DEBUG(166): 7d3aae24 636e6923 6564756c 72413c20 6e697564 #include <Arduin
12-11 00:10:38.146: INFO/DEBUG(166): 7d3aae34 3e682e6f 7274730a 20746375 0a7b2073 o.h>.struct s {.
12-11 00:10:38.146: INFO/DEBUG(166): 7d3aae44 6e692020 3b692074 746e690a 203b6620 int i;.int f;
12-11 00:10:38.146: INFO/DEBUG(166): memory near fp:
12-11 00:10:38.146: INFO/DEBUG(166): 40253a4c 00000000 00000000 00000000 00000000 …
12-11 00:10:38.146: INFO/DEBUG(166): 40253a5c 00000000 00000000 00000000 00000000 …
12-11 00:10:38.146: INFO/DEBUG(166): 40253a6c c6c488f5 00000000 00000000 00000000 …
12-11 00:10:38.146: INFO/DEBUG(166): 40253a7c 00000000 00000000 00000000 00000000 …
12-11 00:10:38.146: INFO/DEBUG(166): 40253a8c 00000000 00000000 00000000 00000000 …
12-11 00:10:38.146: INFO/DEBUG(166): memory near ip:
12-11 00:10:38.146: INFO/DEBUG(166): 00003fe0 ffffffff ffffffff ffffffff ffffffff …
12-11 00:10:38.146: INFO/DEBUG(166): 00003ff0 ffffffff ffffffff ffffffff ffffffff …
12-11 00:10:38.146: INFO/DEBUG(166): 00004000 ffffffff ffffffff ffffffff ffffffff …
12-11 00:10:38.146: INFO/DEBUG(166): 00004010 ffffffff ffffffff ffffffff ffffffff …
12-11 00:10:38.146: INFO/DEBUG(166): 00004020 ffffffff ffffffff ffffffff ffffffff …
12-11 00:10:38.146: INFO/DEBUG(166): memory near sp:
12-11 00:10:38.146: INFO/DEBUG(166): 7e7a8298 00000000 4021ec89 00000001 7e7a82bc …!@…z~
12-11 00:10:38.146: INFO/DEBUG(166): 7e7a82a8 00000002 00000002 df0027ad 00000000 …’…
12-11 00:10:38.146: INFO/DEBUG(166): 7e7a82b8 75ff7ec2 fffffbdf 4023dbfc 00000002 .~.u…#@…
12-11 00:10:38.146: INFO/DEBUG(166): 7e7a82c8 00000002 4021e1f5 40247718 75ff7ec2 …!@.w$@.~.u
12-11 00:10:38.146: INFO/DEBUG(166): 7e7a82d8 4023dbfc 40210c08 7e7a82e0 402220e3 …#@…!@…z~. "@
12-11 00:10:38.146: INFO/DEBUG(166): code around pc:
12-11 00:10:38.146: INFO/DEBUG(166): 4021b308 e000b164 6823461c d1fb2b00 68e3e026 d…F#h.+…&…h
12-11 00:10:38.146: INFO/DEBUG(166): 4021b318 4a17b123 447a2401 47986014 20274911 #…J.$zD.`.G.I’
12-11 00:10:38.146: INFO/DEBUG(166): 4021b328 70082400 eb9cf7f4 f7f52106 a902ecdc .$.p…!..
12-11 00:10:38.146: INFO/DEBUG(166): 4021b338 f04f2006 460a5380 94029304 f7f59403 . O…S.F…
12-11 00:10:38.146: INFO/DEBUG(166): 4021b348 4629e8ba 20024622 e8c2f7f5 eb88f7f4 …)F"F. …
12-11 00:10:38.146: INFO/DEBUG(166): code around lr:
12-11 00:10:38.146: INFO/DEBUG(166): 4021ec68 41f0e92d 4c0b2600 447c4680 68a56824 -…A.&.L.F|D$h.h
12-11 00:10:38.146: INFO/DEBUG(166): 4021ec78 e0076867 300cf9b5 dd022b00 47c04628 gh…0.+…(F.G
12-11 00:10:38.146: INFO/DEBUG(166): 4021ec88 35544306 d5f53f01 2c006824 4630d1ef .CT5.?..$h.,…0F
12-11 00:10:38.146: INFO/DEBUG(166): 4021ec98 81f0e8bd 0002888e 43f0e92d fb01461f …-…C.F…
12-11 00:10:38.146: INFO/DEBUG(166): 4021eca8 f8dff602 b0878058 44f8460c 8000f8d8 …X…F.D…
12-11 00:10:38.146: INFO/DEBUG(166): memory map around fault addr deadbaad:
12-11 00:10:38.146: INFO/DEBUG(166): be8ef000-be910000 [stack]
12-11 00:10:38.146: INFO/DEBUG(166): (no map for address)
12-11 00:10:38.146: INFO/DEBUG(166): ffff0000-ffff1000 [vectors]
12-11 00:10:38.536: INFO/BootReceiver