Fix for memory leak in RSA-SSA signing
Fix in mbedtls_rsa_rsassa_pkcs1_v15_sign() in rsa.c. Resolves github issue #372
diff --git a/library/rsa.c b/library/rsa.c
index 59ec35f..0cb0e7d 100644
--- a/library/rsa.c
+++ b/library/rsa.c
@@ -1082,10 +1082,16 @@
* temporary buffer and check it before returning it.
*/
sig_try = polarssl_malloc( ctx->len );
- verif = polarssl_malloc( ctx->len );
- if( sig_try == NULL || verif == NULL )
+ if( sig_try == NULL )
return( POLARSSL_ERR_MPI_MALLOC_FAILED );
+ verif = polarssl_malloc( ctx->len );
+ if( verif == NULL )
+ {
+ polarssl_free( sig_try );
+ return( POLARSSL_ERR_MPI_MALLOC_FAILED );
+ }
+
MPI_CHK( rsa_private( ctx, f_rng, p_rng, sig, sig_try ) );
MPI_CHK( rsa_public( ctx, sig_try, verif ) );