Init and free new contexts in the right place for SSL to prevent
memory leaks
diff --git a/library/ssl_srv.c b/library/ssl_srv.c
index 451d445..c6a8273 100644
--- a/library/ssl_srv.c
+++ b/library/ssl_srv.c
@@ -1304,7 +1304,6 @@
          *     ECPoint      public;
          * } ServerECDHParams;
          */
-        ecdh_init( &ssl->handshake->ecdh_ctx );
         if( ( ret = ecp_use_known_dp( &ssl->handshake->ecdh_ctx.grp,
                                        ssl->handshake->ec_curve ) ) != 0 )
         {
@@ -1423,6 +1422,13 @@
             md_update( &ctx, ssl->handshake->randbytes, 64 );
             md_update( &ctx, dig_sig, dig_sig_len );
             md_finish( &ctx, hash );
+
+            if( ( ret = md_free_ctx( &ctx ) ) != 0 )
+            {
+                SSL_DEBUG_RET( 1, "md_free_ctx", ret );
+                return( ret );
+            }
+
         }
 
         SSL_DEBUG_BUF( 3, "parameters hash", hash, hashlen );