From cdd73f9ac0ae4b07009d5ba6cdb46db81ab8e52d Mon Sep 17 00:00:00 2001
From: Lee Miller <lee.miller@tutanota.com>
Date: Sun, 26 Jun 2022 16:01:38 +0300
Subject: [PATCH] Move freeing pointers in highlevelcrypto.pointMult() to
 finally branch

like it's done in pyelliptic.
---
 src/highlevelcrypto.py | 7 ++++---
 1 file changed, 4 insertions(+), 3 deletions(-)

diff --git a/src/highlevelcrypto.py b/src/highlevelcrypto.py
index 356cded7..7037bfab 100644
--- a/src/highlevelcrypto.py
+++ b/src/highlevelcrypto.py
@@ -134,9 +134,6 @@ def pointMult(secret):
             mb = OpenSSL.create_string_buffer(size)
             OpenSSL.i2o_ECPublicKey(k, OpenSSL.byref(OpenSSL.pointer(mb)))
 
-            OpenSSL.EC_POINT_free(pub_key)
-            OpenSSL.BN_free(priv_key)
-            OpenSSL.EC_KEY_free(k)
             return mb.raw
 
         except Exception:
@@ -144,3 +141,7 @@ def pointMult(secret):
             import time
             traceback.print_exc()
             time.sleep(0.2)
+        finally:
+            OpenSSL.EC_POINT_free(pub_key)
+            OpenSSL.BN_free(priv_key)
+            OpenSSL.EC_KEY_free(k)