Fix global ref leak in android.media.AudioRecord. Delete global refs

to the native AudioRecord pointer and the callback cookie (for native
to Java calls) in the finalize() function and when an error occurs
during the allocation of the native resources.
This commit is contained in:
Jean-Michel Trivi
2009-07-17 12:05:31 -07:00
parent 19e53f7ae5
commit 4bac5a3928

View File

@@ -212,8 +212,10 @@ android_media_AudioRecord_setup(JNIEnv *env, jobject thiz, jobject weak_this,
// failure:
native_init_failure:
env->DeleteGlobalRef(lpCallbackData->audioRecord_class);
env->DeleteGlobalRef(lpCallbackData->audioRecord_ref);
delete lpCallbackData;
native_track_failure:
delete lpRecorder;
@@ -274,6 +276,8 @@ static void android_media_AudioRecord_finalize(JNIEnv *env, jobject thiz) {
thiz, javaAudioRecordFields.nativeCallbackCookie);
if (lpCookie) {
LOGV("deleting lpCookie: %x\n", (int)lpCookie);
env->DeleteGlobalRef(lpCookie->audioRecord_class);
env->DeleteGlobalRef(lpCookie->audioRecord_ref);
delete lpCookie;
}