diff runes.py @ 14:152f6aa87d62

Plug a memoryview leak.
author David Barts <n5jrn@me.com>
date Fri, 27 Dec 2019 13:30:44 -0800
parents 6acda841a690
children 0be0586104b7
line wrap: on
line diff
--- a/runes.py	Fri Dec 27 13:23:07 2019 -0800
+++ b/runes.py	Fri Dec 27 13:30:44 2019 -0800
@@ -155,12 +155,15 @@
         view = memoryview(self.buffer)
         try:
             ret = view[key]
-            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")
+            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()
         except IndexError:
             return ""
         finally: