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

Fixed leaks in Java wrapper

parent 54b4661a
......@@ -266,8 +266,8 @@ class JavaTranslator(object):
methodDict['hasNormalReturn'] = not methodDict['hasListReturn'] and not methodDict['hasStringReturn'] and not methodDict['hasByteArrayReturn']
methodDict['name'] = 'Java_' + self.jni_package + className + 'Impl_' + _method.name.translate(self.nameTranslator)
methodDict['notStatic'] = not static
methodDict['isConstList'] = _method.returnType.isconst
methodDict['isNotConstList'] = not _method.returnType.isconst
methodDict['isConst'] = _method.returnType.isconst
methodDict['isNotConst'] = not _method.returnType.isconst
if _method.name.to_c()[-1].isdigit():
methodDict['name'] += _method.name.to_c()[-1]
......@@ -416,6 +416,7 @@ class JavaTranslator(object):
methodDict['jniUpcallMethod'] = 'CallVoidMethod'
methodDict['isJniUpcallBasicType'] = False
methodDict['isJniUpcallObject'] = False
if isinstance(_method.returnType, AbsApi.ClassType):
methodDict['jniUpcallMethod'] = 'CallObjectMethod'
methodDict['isJniUpcallObject'] = True
......@@ -666,6 +667,8 @@ class Jni(object):
'cPrefix': jniInterface.cPrefix,
'jniPackage': self.jni_package,
'factoryName': javaClass.factoryName,
'isCore': jniInterface.cPrefix == 'linphone_core',
'isNotCore': not jniInterface.cPrefix == 'linphone_core',
'callbacksList': []
}
for callback in jniInterface.callbacks:
......
......@@ -510,7 +510,7 @@ JNIEXPORT void JNICALL Java_{{jniPackage}}{{className}}Impl_removeListener(JNIEn
bctbx_error("Java_{{jniPackage}}{{className}}Impl_removeListener's {{classCName}} C ptr is null!");
return;
}
const bctbx_list_t *cbs_list = {{cPrefix}}_get_callbacks_list(cptr);
{{#isNotCore}}const {{/isNotCore}}bctbx_list_t *cbs_list = {{cPrefix}}_get_callbacks_list(cptr);
bctbx_list_t *it;
for (it = (bctbx_list_t *)cbs_list; it != nullptr; it = it->next) {
{{classCName}}Cbs *cbs = ({{classCName}}Cbs *)it->data;
......@@ -522,6 +522,7 @@ JNIEXPORT void JNICALL Java_{{jniPackage}}{{className}}Impl_removeListener(JNIEn
break;
}
}
{{#isCore}}bctbx_list_free(cbs_list);{{/isCore}}
}
{{/isMultiListener}}
{{/interfaces}}
......@@ -575,7 +576,7 @@ JNIEXPORT {{return}} JNICALL {{name}}({{params}}) {
{{/isObjList}}
}
{{/lists}}{{#hasListReturn}}
{{#isConstList}}const {{/isConstList}}bctbx_list_t *list = {{c_name}}({{#notStatic}}cptr{{/notStatic}}{{params_impl}});
{{#isConst}}const {{/isConst}}bctbx_list_t *list = {{c_name}}({{#notStatic}}cptr{{/notStatic}}{{params_impl}});
bctbx_list_t *list_it = (bctbx_list_t *)list;
size_t count = bctbx_list_size(list);
{{#isRealObjectArray}}
......@@ -597,7 +598,7 @@ JNIEXPORT {{return}} JNICALL {{name}}({{params}}) {
list_it = bctbx_list_next(list_it);
i += 1;
}
{{#isNotConstList}}bctbx_list_free(list);{{/isNotConstList}}
{{#isNotConst}}bctbx_list_free(list);{{/isNotConst}}
{{/hasListReturn}}{{#hasByteArrayReturn}}
{{c_type_return}} jni_result = {{c_name}}({{#notStatic}}cptr{{/notStatic}}{{params_impl}});
if (!jni_result) return nullptr;
......@@ -606,8 +607,9 @@ JNIEXPORT {{return}} JNICALL {{name}}({{params}}) {
env->SetByteArrayRegion(array, 0, (int)jni_result_length, (const jbyte*)jni_result);
return array;
{{/hasByteArrayReturn}}{{#hasStringReturn}}
const char *c_string = {{c_name}}({{#notStatic}}cptr{{/notStatic}}{{params_impl}}){{#returnObject}}){{/returnObject}};
{{#isConst}}const {{/isConst}}char *c_string = {{c_name}}({{#notStatic}}cptr{{/notStatic}}{{params_impl}}){{#returnObject}}){{/returnObject}};
jstring jni_result = (c_string != nullptr) ? get_jstring_from_char(env, c_string) : nullptr;
{{#isNotConst}}bctbx_free(c_string);{{/isNotConst}}
{{/hasStringReturn}}{{#hasNormalReturn}}
{{#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}}
......
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