From c15b02f2711def8a90249cc11d6cdbeabdadce4f Mon Sep 17 00:00:00 2001 From: Ghislain MARY Date: Thu, 31 Jul 2014 14:53:09 +0200 Subject: [PATCH] Add Python refcount increment in dealloc method to prevent reentrancy. --- tools/python/apixml2python/linphone.py | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/tools/python/apixml2python/linphone.py b/tools/python/apixml2python/linphone.py index 561c840ec..b8520d353 100644 --- a/tools/python/apixml2python/linphone.py +++ b/tools/python/apixml2python/linphone.py @@ -432,15 +432,16 @@ class DeallocMethodDefinition(MethodDefinition): return "\tpylinphone_trace(1, \"[PYLINPHONE] >>> %s(%p [%p])\", __FUNCTION__, self, native_ptr);\n" def format_c_function_call(self): - native_ptr_dealloc_code = '' + # Increment the refcount on self to prevent reentrancy in the dealloc method. + native_ptr_dealloc_code = "\tPy_INCREF(self);\n" if self.class_['class_refcountable']: - native_ptr_dealloc_code = \ + native_ptr_dealloc_code += \ """ if (native_ptr != NULL) {{ {function_prefix}unref(native_ptr); }} """.format(function_prefix=self.class_['class_c_function_prefix']) elif self.class_['class_destroyable']: - native_ptr_dealloc_code = \ + native_ptr_dealloc_code += \ """ if (native_ptr != NULL) {{ {function_prefix}destroy(native_ptr); }}