Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 4ce27b51 authored by Jean-Michel Trivi's avatar Jean-Michel Trivi
Browse files

AudioRecord JNI: fix mem leak on audio_attributes_t

Free memory calloc'd to hold audio_attributes_t for the
  AudioRecord instance.

Bug: 109700675
Test: see bug
Change-Id: I688c6d2ee4a2db5a4d96b54e33bcc7237daef235
parent 9a184cb7
Loading
Loading
Loading
Loading
+9 −0
Original line number Diff line number Diff line
@@ -368,10 +368,19 @@ android_media_AudioRecord_setup(JNIEnv *env, jobject thiz, jobject weak_this,
    // of the Java object (in mNativeCallbackCookie) so we can free the memory in finalize()
    env->SetLongField(thiz, javaAudioRecordFields.nativeCallbackCookie, (jlong)lpCallbackData);

    if (paa != NULL) {
        // audio attributes were copied in AudioRecord creation
        free(paa);
        paa = NULL;
    }

    return (jint) AUDIO_JAVA_SUCCESS;

    // failure:
native_init_failure:
    if (paa != NULL) {
        free(paa);
    }
    env->DeleteGlobalRef(lpCallbackData->audioRecord_class);
    env->DeleteGlobalRef(lpCallbackData->audioRecord_ref);
    delete lpCallbackData;