Fix memory leaks in example programs.
diff --git a/programs/pkey/rsa_encrypt.c b/programs/pkey/rsa_encrypt.c
index 6831833..0e9b9e3 100644
--- a/programs/pkey/rsa_encrypt.c
+++ b/programs/pkey/rsa_encrypt.c
@@ -68,6 +68,7 @@
unsigned char buf[512];
const char *pers = "rsa_encrypt";
+ rsa_init( &rsa, RSA_PKCS_V15, 0 );
ret = 1;
if( argc != 2 )
@@ -104,8 +105,6 @@
goto exit;
}
- rsa_init( &rsa, RSA_PKCS_V15, 0 );
-
if( ( ret = mpi_read_file( &rsa.N, 16, f ) ) != 0 ||
( ret = mpi_read_file( &rsa.E, 16, f ) ) != 0 )
{
@@ -160,6 +159,7 @@
exit:
ctr_drbg_free( &ctr_drbg );
entropy_free( &entropy );
+ rsa_free( &rsa );
#if defined(_WIN32)
polarssl_printf( " + Press Enter to exit this program.\n" );