diff options
| author | Peter LaFosse <peter@vector35.com> | 2026-05-27 17:18:30 -0400 |
|---|---|---|
| committer | Peter LaFosse <peter@vector35.com> | 2026-05-27 17:18:30 -0400 |
| commit | 6ce58cb5b8355ada533e7bf5e5c10ec0ff76bc92 (patch) | |
| tree | 215b542b3e1a6fa3553907ddbe088877ed6105f9 | |
| parent | 162b406ea28aa5bacc34a00745d8780bcbf58753 (diff) | |
Guard disposed BinaryView handles
| -rw-r--r-- | python/binaryview.py | 16 |
1 files changed, 12 insertions, 4 deletions
diff --git a/python/binaryview.py b/python/binaryview.py index 5594b066..5a63248f 100644 --- a/python/binaryview.py +++ b/python/binaryview.py @@ -3197,7 +3197,7 @@ class BinaryView: _handle = core.BNCreateCustomBinaryView(self.__class__.name, file_metadata.handle, _parent_view, self._cb) assert _handle is not None - self.handle = _handle + self._handle = _handle self._notifications = {} self._parse_only = False self._preload_limit = 5 @@ -3210,9 +3210,9 @@ class BinaryView: for i in self._notifications.values(): i._unregister() self._notifications.clear() - if self.handle is not None: - core.BNFreeBinaryView(self.handle) - self.handle = None + if self._handle is not None: + core.BNFreeBinaryView(self._handle) + self._handle = None def __enter__(self) -> 'BinaryView': return self @@ -3225,6 +3225,8 @@ class BinaryView: self._cleanup() def __repr__(self): + if self._handle is None: + return "<BinaryView: disposed>" start = self.start length = self.length if start != 0: @@ -3240,6 +3242,12 @@ class BinaryView: def length(self): return int(core.BNGetViewLength(self.handle)) + @property + def handle(self): + if self._handle is None: + raise ReferenceError("BinaryView has been disposed") + return self._handle + def __bool__(self): return True |
