Cleaned up location of init and free for some programs to prevent memory
leaks on incorrect arguments
diff --git a/programs/ssl/ssl_server.c b/programs/ssl/ssl_server.c
index a4247da..87e9ef2 100644
--- a/programs/ssl/ssl_server.c
+++ b/programs/ssl/ssl_server.c
@@ -101,9 +101,13 @@
((void) argc);
((void) argv);
+ memset( &ssl, 0, sizeof(ssl_context) );
#if defined(POLARSSL_SSL_CACHE_C)
ssl_cache_init( &cache );
#endif
+ memset( &srvcert, 0, sizeof( x509_cert ) );
+ rsa_init( &rsa, RSA_PKCS_V15, 0 );
+ entropy_init( &entropy );
/*
* 1. Load the certificates and private RSA key
@@ -111,8 +115,6 @@
printf( "\n . Loading the server cert. and key..." );
fflush( stdout );
- memset( &srvcert, 0, sizeof( x509_cert ) );
-
/*
* This demonstration program uses embedded test certificates.
* Instead, you may want to use x509parse_crtfile() to read the
@@ -134,7 +136,6 @@
goto exit;
}
- rsa_init( &rsa, RSA_PKCS_V15, 0 );
ret = x509parse_key( &rsa, (const unsigned char *) test_srv_key,
strlen( test_srv_key ), NULL, 0 );
if( ret != 0 )
@@ -165,7 +166,6 @@
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 )
@@ -353,7 +353,9 @@
}
#endif
- net_close( client_fd );
+ if( client_fd != -1 )
+ net_close( client_fd );
+
x509_free( &srvcert );
rsa_free( &rsa );
ssl_free( &ssl );