From dfd447e83642e262cb03ebf2bff7355da9191048 Mon Sep 17 00:00:00 2001 From: Jens Wiklander Date: Thu, 17 Jan 2019 13:30:57 +0100 Subject: [PATCH] fix memory leak in mpi_miller_rabin() Fixes memory leak in mpi_miller_rabin() that occurs when the function has failed to obtain a usable random 'A' 30 turns in a row. Signed-off-by: Jens Wiklander --- library/bignum.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/library/bignum.c b/library/bignum.c index d3d02b1a0..606bca456 100644 --- a/library/bignum.c +++ b/library/bignum.c @@ -2329,7 +2329,8 @@ static int mpi_miller_rabin( const mbedtls_mpi *X, size_t rounds, } if (count++ > 30) { - return MBEDTLS_ERR_MPI_NOT_ACCEPTABLE; + ret = MBEDTLS_ERR_MPI_NOT_ACCEPTABLE; + goto cleanup; } } while ( mbedtls_mpi_cmp_mpi( &A, &W ) >= 0 ||