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

@ -108,6 +108,12 @@ int main( int argc, char *argv[] )
((void) argc);
((void) argv);
memset( &ssl, 0, sizeof(ssl_context) );
entropy_init( &entropy );
pk_init( &pkey );
x509_crt_init( &srvcert );
signal( SIGCHLD, SIG_IGN );
/*
@ -116,7 +122,6 @@ int main( int argc, char *argv[] )
printf( "\n . Initial seeding of the random generator..." );
fflush( stdout );
entropy_init( &entropy );
if( ( ret = ctr_drbg_init( &ctr_drbg, entropy_func, &entropy,
(const unsigned char *) pers,
strlen( pers ) ) ) != 0 )
@ -133,8 +138,6 @@ int main( int argc, char *argv[] )
printf( " . 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
@ -156,7 +159,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 )
@ -246,7 +248,7 @@ int main( int argc, char *argv[] )
printf( " failed\n ! ctr_drbg_reseed returned %d\n", ret );
goto exit;
}
if( ( ret = ssl_init( &ssl ) ) != 0 )
{
printf( " failed\n ! ssl_init returned %d\n\n", ret );
@ -360,7 +362,9 @@ int main( int argc, char *argv[] )
exit:
net_close( client_fd );
if( client_fd != -1 )
net_close( client_fd );
x509_crt_free( &srvcert );
pk_free( &pkey );
ssl_free( &ssl );