From 5f8fb25f64f6970fbd0c710c9f22320229d45162 Mon Sep 17 00:00:00 2001 From: Dmitry Kovalenko Date: Mon, 16 May 2016 00:27:13 +0200 Subject: [PATCH] fix memory leak in mp_init_copy() This closes #59 --- bn_mp_init_copy.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) 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