From d6493e39ab0d85565245139fd66265fc30e6b0cf Mon Sep 17 00:00:00 2001 From: Ryan Snyder Date: Wed, 26 Sep 2018 07:11:37 -0400 Subject: python3: ensure callbacks live long enough --- python/downloadprovider.py | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) (limited to 'python/downloadprovider.py') diff --git a/python/downloadprovider.py b/python/downloadprovider.py index eb9735f3..10f9dee1 100644 --- a/python/downloadprovider.py +++ b/python/downloadprovider.py @@ -39,6 +39,7 @@ from binaryninja import range class DownloadInstance(object): + _registered_instances = [] def __init__(self, provider, handle = None): if handle is None: self._cb = core.BNDownloadInstanceCallbacks() @@ -46,15 +47,18 @@ class DownloadInstance(object): self._cb.destroyInstance = self._cb.destroyInstance.__class__(self._destroy_instance) self._cb.performRequest = self._cb.performRequest.__class__(self._perform_request) self.handle = core.BNInitDownloadInstance(provider.handle, self._cb) + self.__class__._registered_instances.append(self) else: self.handle = core.handle_of_type(handle, core.BNDownloadInstance) - self._outputCallbacks = None + self._must_free = handle is not None def __del__(self): - core.BNFreeDownloadInstance(self.handle) + if self._must_free: + core.BNFreeDownloadInstance(self.handle) def _destroy_instance(self, ctxt): try: + self.__class__._registered_instances.remove(self) self.perform_destroy_instance() except: log.log_error(traceback.format_exc()) -- cgit v1.3.1