From 88c902d12dea1fe5332c3a8a3b0e8bd63e4690a2 Mon Sep 17 00:00:00 2001 From: Ghislain MARY Date: Thu, 18 Dec 2014 16:07:07 +0100 Subject: [PATCH] Fix memory leak of returned strings in Python module. --- tools/python/apixml2python/linphone.py | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/tools/python/apixml2python/linphone.py b/tools/python/apixml2python/linphone.py index 751e0b367..a4f6f8a2d 100644 --- a/tools/python/apixml2python/linphone.py +++ b/tools/python/apixml2python/linphone.py @@ -382,6 +382,7 @@ class MethodDefinition: from_native_pointer_code = '' convert_from_code = '' build_value_code = '' + cfree_code = '' result_variable = '' if self.return_complete_type != 'void': if self.build_value_format == 'O': @@ -400,16 +401,20 @@ class MethodDefinition: result_variable = 'cresult' if result_variable != '': build_value_code = "pyret = Py_BuildValue(\"{fmt}\", {result_variable});".format(fmt=self.build_value_format, result_variable=result_variable) + if self.return_complete_type == 'char *': + cfree_code = 'ms_free(cresult);'; body = \ """ {c_function_call_code} pylinphone_dispatch_messages(); {from_native_pointer_code} {convert_from_code} {build_value_code} + {cfree_code} """.format(c_function_call_code=c_function_call_code, from_native_pointer_code=from_native_pointer_code, convert_from_code=convert_from_code, - build_value_code=build_value_code) + build_value_code=build_value_code, + cfree_code=cfree_code) return body def format_return_trace(self):