Commit c8797562 authored by Sylvain Berfini's avatar Sylvain Berfini 🎩

Fixed leak in Java wrapper in all _create methods

parent e81e5f31
......@@ -272,6 +272,8 @@ class JavaTranslator(object):
else:
methodDict['c_name'] = _method.name.to_c()
methodDict['takeRefOnReturnedObject'] = "FALSE" if 'create' in _method.name.to_c() else "TRUE"
methodDict['returnObject'] = methodDict['hasReturn'] and type(_method.returnType) is AbsApi.ClassType
methodDict['returnClassName'] = _method.returnType.translate(self.langTranslator, namespace=namespace)
methodDict['isRealObjectArray'] = False
......
......@@ -242,7 +242,7 @@ extern "C" {
#endif
{{#objects}}
jobject get{{className}}(JNIEnv *env, {{classCName}} *cptr) {
jobject get{{className}}(JNIEnv *env, {{classCName}} *cptr, bool_t takeref) {
jobject jobj = 0;
if (cptr != NULL) {
......@@ -259,7 +259,8 @@ jobject get{{className}}(JNIEnv *env, {{classCName}} *cptr) {
if (up == NULL) {
jobj = env->NewObject({{cPrefix}}_class, {{cPrefix}}_constructor, (jlong)cptr);
belle_sip_object_data_set((belle_sip_object_t *)cptr, belle_sip_java_user_data_key, (void*)env->NewWeakGlobalRef(jobj), NULL);
{{#refCountable}}{{cPrefix}}_ref(cptr);{{/refCountable}}
if (takeref)
{{#refCountable}}{{cPrefix}}_ref(cptr);{{/refCountable}}
} else {
jobj = env->NewLocalRef((jobject)up);
if (jobj == NULL) {
......@@ -268,7 +269,8 @@ jobject get{{className}}(JNIEnv *env, {{classCName}} *cptr) {
// takes implicit local ref
jobj = env->NewObject({{cPrefix}}_class, {{cPrefix}}_constructor, (jlong)cptr);
belle_sip_object_data_set((belle_sip_object_t *)cptr, belle_sip_java_user_data_key, (void*)env->NewWeakGlobalRef(jobj), NULL);
{{#refCountable}}{{cPrefix}}_ref(cptr);{{/refCountable}}
if (takeref)
{{#refCountable}}{{cPrefix}}_ref(cptr);{{/refCountable}}
}
}
}
......@@ -323,7 +325,7 @@ static {{return}} {{callbackName}}({{params}}) {
env->DeleteLocalRef(jlistenerClass);
{{#jobjects}}
jobject j_{{objectName}} = get{{className}}(env, (Linphone{{className}} *){{objectName}});
jobject j_{{objectName}} = get{{className}}(env, (Linphone{{className}} *){{objectName}}, TRUE);
{{/jobjects}}
{{#jenums}}
LinphoneJavaBindings *ljb = (LinphoneJavaBindings *)linphone_factory_get_user_data(linphone_factory_get());
......@@ -483,7 +485,7 @@ jobject Java_{{jni_package}}CoreImpl_getMediastreamerFactory(JNIEnv *env, jobjec
for (size_t i = 0; i < count; i++) {
{{#isRealObjectArray}}
{{objectClassCName}}* c_object = ({{objectClassCName}}*)list->data;
jobject object = get{{objectClassName}}(env, c_object);
jobject object = get{{objectClassName}}(env, c_object, TRUE); //TODO
{{/isRealObjectArray}}
{{#isStringObjectArray}}const char *cstring = (const char *)list->data;
jstring object = cstring ? get_jstring_from_char(env, cstring) : 0;{{/isStringObjectArray}}
......@@ -505,7 +507,7 @@ jobject Java_{{jni_package}}CoreImpl_getMediastreamerFactory(JNIEnv *env, jobjec
const char *c_string = {{c_name}}({{#notStatic}}cptr{{/notStatic}}{{params_impl}}){{#returnObject}}){{/returnObject}};
jstring jni_result = (c_string != NULL) ? get_jstring_from_char(env, c_string) : NULL;
{{/hasStringReturn}}{{#hasNormalReturn}}
{{#hasReturn}}{{return}} jni_result = ({{return}}){{#returnObject}}get{{returnClassName}}(env, (Linphone{{returnClassName}} *){{/returnObject}}{{/hasReturn}}{{c_name}}({{#notStatic}}cptr{{/notStatic}}{{params_impl}}){{#returnObject}}){{/returnObject}};
{{#hasReturn}}{{return}} jni_result = ({{return}}){{#returnObject}}get{{returnClassName}}(env, (Linphone{{returnClassName}} *){{/returnObject}}{{/hasReturn}}{{c_name}}({{#notStatic}}cptr{{/notStatic}}{{params_impl}}){{#returnObject}}, {{takeRefOnReturnedObject}}){{/returnObject}};
{{/hasNormalReturn}}{{#strings}}
ReleaseStringUTFChars(env, {{string}}, c_{{string}});
{{/strings}}{{#bytes}}
......@@ -574,7 +576,7 @@ void Java_org_linphone_core_CoreImpl_setNativeVideoWindowId(JNIEnv *env, jobject
}
jobject Java_org_linphone_core_FactoryImpl_getCore(JNIEnv *env, jobject thiz, jlong ptr, jlong lcPtr) {
return getCore(env, (LinphoneCore*)lcPtr);
return getCore(env, (LinphoneCore*)lcPtr, TRUE);
}
#ifdef __cplusplus
......
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