1
0
mirror of https://github.com/Mbed-TLS/mbedtls.git synced 2025-07-29 11:41:15 +03:00

Cleaned up location of init and free for some programs to prevent memory

leaks on incorrect arguments
This commit is contained in:
Paul Bakker
2014-04-17 16:02:36 +02:00
parent cbe3d0d5cc
commit 0c22610693
19 changed files with 95 additions and 48 deletions

View File

@ -100,9 +100,13 @@ int main( int argc, char *argv[] )
((void) argc);
((void) argv);
memset( &ssl, 0, sizeof(ssl_context) );
#if defined(POLARSSL_SSL_CACHE_C)
ssl_cache_init( &cache );
#endif
x509_crt_init( &srvcert );
pk_init( &pkey );
entropy_init( &entropy );
/*
* 1. Load the certificates and private RSA key
@ -110,8 +114,6 @@ int main( int argc, char *argv[] )
printf( "\n . Loading the server cert. and key..." );
fflush( stdout );
x509_crt_init( &srvcert );
/*
* This demonstration program uses embedded test certificates.
* Instead, you may want to use x509_crt_parse_file() to read the
@ -133,7 +135,6 @@ int main( int argc, char *argv[] )
goto exit;
}
pk_init( &pkey );
ret = pk_parse_key( &pkey, (const unsigned char *) test_srv_key,
strlen( test_srv_key ), NULL, 0 );
if( ret != 0 )
@ -164,7 +165,6 @@ int main( int argc, char *argv[] )
printf( " . Seeding the random number generator..." );
fflush( stdout );
entropy_init( &entropy );
if( ( ret = ctr_drbg_init( &ctr_drbg, entropy_func, &entropy,
(const unsigned char *) pers,
strlen( pers ) ) ) != 0 )
@ -352,7 +352,9 @@ exit:
}
#endif
net_close( client_fd );
if( client_fd != -1 )
net_close( client_fd );
x509_crt_free( &srvcert );
pk_free( &pkey );
ssl_free( &ssl );