Commit b87dd9f1 authored by Sylvain Berfini's avatar Sylvain Berfini 🐮
Browse files

Fixed another leak in Java wrapper caused by listeners

parent 068cd9ce
...@@ -357,28 +357,36 @@ static {{return}} {{callbackName}}({{params}}) { ...@@ -357,28 +357,36 @@ static {{return}} {{callbackName}}({{params}}) {
{{#interfaces}} {{#interfaces}}
{{#isSingleListener}} {{#isSingleListener}}
void Java_{{jniPackage}}{{className}}Impl_setListener(JNIEnv* env, jobject thiz, jlong ptr, jobject jlistener) { void Java_{{jniPackage}}{{className}}Impl_setListener(JNIEnv* env, jobject thiz, jlong ptr, jobject jlistener) {
{{classCName}} *cptr = ({{classCName}}*)ptr;
{{classCName}}Cbs *cbs = {{cPrefix}}_get_callbacks(cptr);
if (jlistener == NULL) {
jobject listener = (jobject) {{cPrefix}}_cbs_get_user_data(cbs);
{{cPrefix}}_cbs_set_user_data(cbs, NULL);
if (listener != NULL) {
env->DeleteGlobalRef(listener);
}
} else {
jobject listener = env->NewGlobalRef(jlistener);
{{cPrefix}}_cbs_set_user_data(cbs, listener);
{{#callbacksList}}
{{cPrefix}}_cbs_set_{{callback}}(cbs, {{callbackName}});
{{/callbacksList}}
}
}
{{/isSingleListener}} {{/isSingleListener}}
{{#isMultiListener}} {{#isMultiListener}}
void Java_{{jniPackage}}{{className}}Impl_addListener(JNIEnv* env, jobject thiz, jlong ptr, jobject jlistener) { void Java_{{jniPackage}}{{className}}Impl_addListener(JNIEnv* env, jobject thiz, jlong ptr, jobject jlistener) {
{{/isMultiListener}}
{{classCName}} *cptr = ({{classCName}}*)ptr; {{classCName}} *cptr = ({{classCName}}*)ptr;
jobject listener = env->NewGlobalRef(jlistener); jobject listener = env->NewGlobalRef(jlistener);
{{#isSingleListener}}
{{classCName}}Cbs *cbs = {{cPrefix}}_get_callbacks(cptr);
{{/isSingleListener}}
{{#isMultiListener}}
{{classCName}}Cbs *cbs = linphone_factory_create_{{factoryName}}_cbs(NULL); {{classCName}}Cbs *cbs = linphone_factory_create_{{factoryName}}_cbs(NULL);
{{/isMultiListener}}
{{cPrefix}}_cbs_set_user_data(cbs, listener); {{cPrefix}}_cbs_set_user_data(cbs, listener);
{{#callbacksList}} {{#callbacksList}}
{{cPrefix}}_cbs_set_{{callback}}(cbs, {{callbackName}}); {{cPrefix}}_cbs_set_{{callback}}(cbs, {{callbackName}});
{{/callbacksList}} {{/callbacksList}}
{{#isMultiListener}}
{{cPrefix}}_add_callbacks(cptr, cbs); {{cPrefix}}_add_callbacks(cptr, cbs);
{{cPrefix}}_cbs_unref(cbs); {{cPrefix}}_cbs_unref(cbs);
{{/isMultiListener}}
} }
{{#isMultiListener}}
void Java_{{jniPackage}}{{className}}Impl_removeListener(JNIEnv* env, jobject thiz, jlong ptr, jobject jlistener) { void Java_{{jniPackage}}{{className}}Impl_removeListener(JNIEnv* env, jobject thiz, jlong ptr, jobject jlistener) {
{{classCName}} *cptr = ({{classCName}}*)ptr; {{classCName}} *cptr = ({{classCName}}*)ptr;
...@@ -396,7 +404,6 @@ void Java_{{jniPackage}}{{className}}Impl_removeListener(JNIEnv* env, jobject th ...@@ -396,7 +404,6 @@ void Java_{{jniPackage}}{{className}}Impl_removeListener(JNIEnv* env, jobject th
} }
} }
{{/isMultiListener}} {{/isMultiListener}}
{{/interfaces}} {{/interfaces}}
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment