changeset 15:0be0586104b7

Plug the leak properly (I hope).
author David Barts <n5jrn@me.com>
date Fri, 27 Dec 2019 13:35:51 -0800
parents 152f6aa87d62
children 61772bf1f77c
files runes.py
diffstat 1 files changed, 9 insertions(+), 10 deletions(-) [+]
line wrap: on
line diff
--- a/runes.py	Fri Dec 27 13:30:44 2019 -0800
+++ b/runes.py	Fri Dec 27 13:35:51 2019 -0800
@@ -154,16 +154,15 @@
     def __getitem__(self, key):
         view = memoryview(self.buffer)
         try:
-            ret = view[key]
-            try:
-                if isinstance (ret, int):
-                    return chr(ret)
-                elif isinstance(ret, memoryview):
-                    return self.codec.decode(ret, 'replace')[0]
-                else:
-                    raise AssertionError("this shouldn't happen")
-            finally:
-                ret.release()
+            result = view[key]
+            if isinstance (result, int):
+                return chr(result)
+            if isinstance(result, memoryview):
+                ret = self.codec.decode(result, 'replace')[0]
+                result.release()
+                return ret
+            else:
+                raise AssertionError("this shouldn't happen")
         except IndexError:
             return ""
         finally: