Skip to content

Commit

Permalink
[ON-40378] Fix crash in wakelock.c regarding releasing JNI references.
Browse files Browse the repository at this point in the history
  • Loading branch information
Carmen Alvarez committed Jul 28, 2016
1 parent 6a8f281 commit 1c6f084
Showing 1 changed file with 4 additions and 3 deletions.
7 changes: 4 additions & 3 deletions src/wakelock.c
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@ void belle_sip_wake_lock_init(JNIEnv *env, jobject pm) {
jfieldID fieldID;

(*env)->GetJavaVM(env, &ctx.jvm);
ctx.powerManager = (*env)->NewGlobalRef(env, pm);
pthread_key_create(&ctx.jniEnvKey, jni_key_cleanup);

powerManagerClass = (*env)->FindClass(env, "android/os/PowerManager");
Expand All @@ -45,10 +44,12 @@ void belle_sip_wake_lock_init(JNIEnv *env, jobject pm) {
} else {
belle_sip_warning("bellesip_wake_lock_init(): the wakelock system has already been initialized");
}
if (ctx.powerManager == NULL) {
ctx.powerManager = (*env)->NewGlobalRef(env, pm);
}
}

void belle_sip_wake_lock_uninit(JNIEnv *env) {
ctx.jvm = NULL;
if(ctx.powerManager != NULL) {
(*env)->DeleteGlobalRef(env, ctx.powerManager);
ctx.powerManager = NULL;
Expand All @@ -61,7 +62,7 @@ void belle_sip_wake_lock_uninit(JNIEnv *env) {
* @param data Unused.
*/
static void jni_key_cleanup(void *data) {
JNIEnv *env = pthread_getspecific(ctx.jniEnvKey);
JNIEnv *env = (JNIEnv*) data;
belle_sip_message("Thread end. Cleanup wake lock jni environment");
if(env != NULL) {
if(ctx.jvm != NULL) {
Expand Down

0 comments on commit 1c6f084

Please sign in to comment.