Cleaned up location of init and free for some programs to prevent memory
leaks on incorrect arguments
diff --git a/programs/ssl/ssl_fork_server.c b/programs/ssl/ssl_fork_server.c
index 76c782b..7e489da 100644
--- a/programs/ssl/ssl_fork_server.c
+++ b/programs/ssl/ssl_fork_server.c
@@ -110,6 +110,12 @@
((void) argc);
((void) argv);
+ memset( &ssl, 0, sizeof(ssl_context) );
+
+ entropy_init( &entropy );
+ rsa_init( &rsa, RSA_PKCS_V15, 0 );
+ memset( &srvcert, 0, sizeof( x509_cert ) );
+
signal( SIGCHLD, SIG_IGN );
/*
@@ -118,7 +124,6 @@
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 )
@@ -135,8 +140,6 @@
printf( " . 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
@@ -158,7 +161,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 )
@@ -248,7 +250,7 @@
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 );
@@ -362,7 +364,9 @@
exit:
- net_close( client_fd );
+ if( client_fd != -1 )
+ net_close( client_fd );
+
x509_free( &srvcert );
rsa_free( &rsa );
ssl_free( &ssl );