From 4380d7b7f30785b6bacc032b68f19f2e2a47d786 Mon Sep 17 00:00:00 2001 From: Gilles Peskine Date: Wed, 16 Nov 2022 22:20:59 +0100 Subject: [PATCH] Simplify cleanup logic Take advantage of the fact that there's a single point of failure. Signed-off-by: Gilles Peskine --- library/bignum_core.c | 17 +++++------------ 1 file changed, 5 insertions(+), 12 deletions(-) diff --git a/library/bignum_core.c b/library/bignum_core.c index 737e08df2f..a8879b327f 100644 --- a/library/bignum_core.c +++ b/library/bignum_core.c @@ -632,10 +632,6 @@ int mbedtls_mpi_core_exp_mod( mbedtls_mpi_uint *X, size_t E_limbs, const mbedtls_mpi_uint *RR ) { - int ret = MBEDTLS_ERR_ERROR_CORRUPTION_DETECTED; - /* heap allocated memory pool */ - mbedtls_mpi_uint *mempool = NULL; - const size_t wsize = exp_mod_get_window_size( E_limbs * biL ); const size_t welem = ( (size_t) 1 ) << wsize; @@ -645,11 +641,12 @@ int mbedtls_mpi_core_exp_mod( mbedtls_mpi_uint *X, const size_t select_limbs = AN_limbs; const size_t total_limbs = table_limbs + temp_limbs + select_limbs; - mempool = mbedtls_calloc( total_limbs, sizeof(mbedtls_mpi_uint) ); + /* heap allocated memory pool */ + mbedtls_mpi_uint *mempool = + mbedtls_calloc( total_limbs, sizeof(mbedtls_mpi_uint) ); if( mempool == NULL ) { - ret = MBEDTLS_ERR_MPI_ALLOC_FAILED; - goto cleanup; + return( MBEDTLS_ERR_MPI_ALLOC_FAILED ); } /* pointers to temporaries within memory pool */ @@ -721,12 +718,8 @@ int mbedtls_mpi_core_exp_mod( mbedtls_mpi_uint *X, const mbedtls_mpi_uint one = 1; mbedtls_mpi_core_montmul( X, X, &one, 1, N, AN_limbs, mm, temp ); - ret = 0; - -cleanup: - mbedtls_free( mempool ); - return( ret ); + return( 0 ); } /* END MERGE SLOT 1 */