-
Notifications
You must be signed in to change notification settings - Fork 49
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix crash in wakelock.c regarding releasing JNI references. #1
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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"); | ||
|
@@ -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); | ||
} | ||
} | ||
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We need |
||
void belle_sip_wake_lock_uninit(JNIEnv *env) { | ||
ctx.jvm = NULL; | ||
if(ctx.powerManager != NULL) { | ||
(*env)->DeleteGlobalRef(env, ctx.powerManager); | ||
ctx.powerManager = NULL; | ||
|
@@ -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; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. http://linux.die.net/man/3/pthread_key_create In the documentation of
When I read this, I don't understand how this ever worked. It looks like There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Hi Carmen,
|
||
belle_sip_message("Thread end. Cleanup wake lock jni environment"); | ||
if(env != NULL) { | ||
if(ctx.jvm != NULL) { | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Since we don't set
ctx.jvm
to NULL anymore, we need to check outside of theif(ctx.jvm == NULL)
block, to assignctx.powerManager