From: Tobias Brunner Date: Mon, 24 Sep 2012 14:56:37 +0000 (+0200) Subject: android: Leak the private key reference on Jelly Bean to avoid a bug in the framework X-Git-Tag: 5.0.1~44 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=94106ddc85f381d4b29d99947af0bd365cb72eb3;p=thirdparty%2Fstrongswan.git android: Leak the private key reference on Jelly Bean to avoid a bug in the framework A bug in the framework on Android Jelly Bean causes a SIGSEGV when the private key object returned from KeyChain.getPrivateKey is garbage collected. Leaking the global reference to that object prevents the garbage collection and thereby the crash. --- diff --git a/src/frontends/android/jni/libandroidbridge/backend/android_private_key.c b/src/frontends/android/jni/libandroidbridge/backend/android_private_key.c index e8a78b5da3..3ed3d75a97 100644 --- a/src/frontends/android/jni/libandroidbridge/backend/android_private_key.c +++ b/src/frontends/android/jni/libandroidbridge/backend/android_private_key.c @@ -232,7 +232,16 @@ METHOD(private_key_t, destroy, void, JNIEnv *env; androidjni_attach_thread(&env); - (*env)->DeleteGlobalRef(env, this->key); + if (android_sdk_version >= ANDROID_JELLY_BEAN) + { /* there is a bug in JB that causes a SIGSEGV if the key object is + * garbage collected so we intentionally leak the reference to it */ + DBG1(DBG_LIB, "intentionally leaking private key reference due to " + "a bug in the framework"); + } + else + { + (*env)->DeleteGlobalRef(env, this->key); + } (*env)->DeleteGlobalRef(env, this->signature_class); androidjni_detach_thread(); this->pubkey->destroy(this->pubkey);