Commit 5f8fb25f64f6970fbd0c710c9f22320229d45162

Dmitry Kovalenko 2016-05-16T00:27:13

fix memory leak in mp_init_copy() This closes #59

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
diff --git a/bn_mp_init_copy.c b/bn_mp_init_copy.c
index 9e15f36..76c5e42 100644
--- a/bn_mp_init_copy.c
+++ b/bn_mp_init_copy.c
@@ -23,7 +23,12 @@ int mp_init_copy (mp_int * a, mp_int * b)
   if ((res = mp_init_size (a, b->used)) != MP_OKAY) {
     return res;
   }
-  return mp_copy (b, a);
+
+  if((res = mp_copy (b, a)) != MP_OKAY) {
+    mp_clear(a);
+  }
+
+  return res;
 }
 #endif