From 5bcfa40f0831c3f2ff266a260e0ca751b092b734 Mon Sep 17 00:00:00 2001 From: Kaz Kylheku Date: Tue, 22 Oct 2019 06:57:32 -0700 Subject: mpi: memory leak in mp_bit. * mpi.c (mp_bit): If the argument is negative, and we have produced a temporary mp_int, we must clear it before returning. --- mpi/mpi.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) (limited to 'mpi/mpi.c') diff --git a/mpi/mpi.c b/mpi/mpi.c index 0e01fc26..e5d76f93 100644 --- a/mpi/mpi.c +++ b/mpi/mpi.c @@ -2404,7 +2404,12 @@ mp_err mp_bit(mp_int *a, mp_size bit) a = &tmp; } - return (digit < USED(a) && (DIGITS(a)[digit] & mask) != 0) ? MP_YES : MP_NO; + res = (digit < USED(a) && (DIGITS(a)[digit] & mask) != 0) ? MP_YES : MP_NO; + + if (a_neg) + mp_clear(&tmp); + + return res; } mp_err mp_to_double(mp_int *mp, double *d) -- cgit v1.2.3