在 android 中的 libc.so 使用 jni 时崩溃
Crashing when using jni at libc.so in android
调用.so中的native方法'sign4Android'后,应用程序崩溃了。代码和日志如下。请帮忙!
代码:
extern "C" JNIEXPORT jstring JNICALL Java_com_XXX_sign_SignHelper_getSign(JNIEnv *env, jobject obj, jstring input){
const char *para = env->GetStringUTFChars(input, 0);
std::string result_c = sign4Android(para);
env->ReleaseStringUTFChars(input, para);
const char *chars = result_c.c_str();
jstring result = env->NewStringUTF(chars);
delete chars;
return result;
}
本机代码方法:
string sign4Android(const char* para);
使用 ndk-stack 记录:
********** Crash dump: **********
Build fingerprint: 'Xiaomi/virgo/virgo:6.0.1/MMB29M/6.3.31:user/release-keys'
pid: 2610, tid: 2610,
signal 11 (SIGSEGV), code 1 (SEGV_MAPERR), fault addr 0xca4007c8
Stack frame #00 pc 00049228 /system/lib/libc.so (arena_run_reg_alloc+87): Routine arena_run_reg_alloc at arena.c:?
Stack frame #01 pc 0004aff9 /system/lib/libc.so (je_arena_tcache_fill_small+104): Routine je_arena_tcache_fill_small at linux-atomic.c:?
Stack frame #02 pc 0005c32b /system/lib/libc.so (je_tcache_alloc_small_hard+18): Routine je_tcache_alloc_small_hard at linux-atomic.c:?
Stack frame #03 pc 00056e1d /system/lib/libc.so (je_malloc+1112): Routine je_malloc at linux-atomic.c:?
Stack frame #04 pc 00021773 /system/lib/libhwui.so: Routine ????:0
Stack frame #05 pc 0002e165 /system/lib/libhwui.so (android::uirenderer::DisplayListCanvas::drawRect(float, float, float, float, SkPaint const&)+156): Routine ????:0
Stack frame #06 pc 72ff926b /data/dalvik-cache/arm/system@framework@boot.oat (offset 0x237a000)
作为Selvin mentions in a
first of all, you shouldn't free char
pointer returned from std:string.c_str()
http://ideone.com/xwUt2R
适合我
调用.so中的native方法'sign4Android'后,应用程序崩溃了。代码和日志如下。请帮忙!
代码:
extern "C" JNIEXPORT jstring JNICALL Java_com_XXX_sign_SignHelper_getSign(JNIEnv *env, jobject obj, jstring input){
const char *para = env->GetStringUTFChars(input, 0);
std::string result_c = sign4Android(para);
env->ReleaseStringUTFChars(input, para);
const char *chars = result_c.c_str();
jstring result = env->NewStringUTF(chars);
delete chars;
return result;
}
本机代码方法:
string sign4Android(const char* para);
使用 ndk-stack 记录:
********** Crash dump: **********
Build fingerprint: 'Xiaomi/virgo/virgo:6.0.1/MMB29M/6.3.31:user/release-keys'
pid: 2610, tid: 2610,
signal 11 (SIGSEGV), code 1 (SEGV_MAPERR), fault addr 0xca4007c8
Stack frame #00 pc 00049228 /system/lib/libc.so (arena_run_reg_alloc+87): Routine arena_run_reg_alloc at arena.c:?
Stack frame #01 pc 0004aff9 /system/lib/libc.so (je_arena_tcache_fill_small+104): Routine je_arena_tcache_fill_small at linux-atomic.c:?
Stack frame #02 pc 0005c32b /system/lib/libc.so (je_tcache_alloc_small_hard+18): Routine je_tcache_alloc_small_hard at linux-atomic.c:?
Stack frame #03 pc 00056e1d /system/lib/libc.so (je_malloc+1112): Routine je_malloc at linux-atomic.c:?
Stack frame #04 pc 00021773 /system/lib/libhwui.so: Routine ????:0
Stack frame #05 pc 0002e165 /system/lib/libhwui.so (android::uirenderer::DisplayListCanvas::drawRect(float, float, float, float, SkPaint const&)+156): Routine ????:0
Stack frame #06 pc 72ff926b /data/dalvik-cache/arm/system@framework@boot.oat (offset 0x237a000)
作为Selvin mentions in a
first of all, you shouldn't free
char
pointer returned fromstd:string.c_str()
http://ideone.com/xwUt2R
适合我