From 8c163706e4d942ee858010a6902da95a7c75f2c3 Mon Sep 17 00:00:00 2001 From: danghvu Date: Wed, 16 Sep 2015 21:33:01 -0500 Subject: [PATCH] Fix issue #113, untracked reference --- bindings/python/unicorn/unicorn.py | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/bindings/python/unicorn/unicorn.py b/bindings/python/unicorn/unicorn.py index 080481ce..f5e1c63e 100644 --- a/bindings/python/unicorn/unicorn.py +++ b/bindings/python/unicorn/unicorn.py @@ -141,6 +141,7 @@ class Uc(object): raise UcError(status) # internal mapping table to save callback & userdata self._callbacks = {} + self._ctype_cbs = {} self._callback_count = 0 @@ -261,6 +262,7 @@ class Uc(object): # save callback & user_data self._callback_count += 1 self._callbacks[self._callback_count] = (callback, user_data) + cb = None if htype in (UC_HOOK_BLOCK, UC_HOOK_CODE): begin = ctypes.c_uint64(arg1) @@ -293,6 +295,9 @@ class Uc(object): status = _uc.uc_hook_add(self._uch, ctypes.byref(_h2), htype, \ cb, ctypes.cast(self._callback_count, ctypes.c_void_p)) + # save the ctype function so gc will leave it alone. + self._ctype_cbs[self._callback_count] = cb + if status != UC_ERR_OK: raise UcError(status)