diff --git a/ChangeLog.d/fix-ecp-mul-memory-leak.txt b/ChangeLog.d/fix-ecp-mul-memory-leak.txt index 2ffd51caf..e82cadc2d 100644 --- a/ChangeLog.d/fix-ecp-mul-memory-leak.txt +++ b/ChangeLog.d/fix-ecp-mul-memory-leak.txt @@ -1,3 +1,3 @@ Bugfix * Fix potential memory leaks in ecp_randomize_jac() and ecp_randomize_mxz() - when PRNG function fails. Contributed by Jonas Lejeune in #3317. + when PRNG function fails. Contributed by Jonas Lejeune in #3318. diff --git a/library/ecp.c b/library/ecp.c index 3c4a91aab..9522edf77 100644 --- a/library/ecp.c +++ b/library/ecp.c @@ -2862,7 +2862,10 @@ int mbedtls_ecp_gen_privkey( const mbedtls_ecp_group *grp, * such as secp224k1 are actually very close to the worst case. */ if( ++count > 30 ) - return( MBEDTLS_ERR_ECP_RANDOM_FAILED ); + { + ret = MBEDTLS_ERR_ECP_RANDOM_FAILED; + goto cleanup; + } ret = mbedtls_mpi_lt_mpi_ct( d, &grp->N, &cmp ); if( ret != 0 )