Update mbedtls_ssl_handshake_free()

Signed-off-by: Xiaofei Bai <xiaofei.bai@arm.com>
diff --git a/library/ssl_tls13_client.c b/library/ssl_tls13_client.c
index b3272c9..8751787 100644
--- a/library/ssl_tls13_client.c
+++ b/library/ssl_tls13_client.c
@@ -1473,7 +1473,7 @@
 
         mbedtls_ssl_handshake_params *handshake = ssl->handshake;
         handshake->certificate_request_context =
-                mbedtls_calloc( 1, certificate_request_context_len);
+                mbedtls_calloc( 1, certificate_request_context_len );
         if( handshake->certificate_request_context == NULL )
         {
             MBEDTLS_SSL_DEBUG_MSG( 1, ( "buffer too small" ) );
@@ -1523,7 +1523,11 @@
                 {
                     MBEDTLS_SSL_DEBUG_MSG( 3,
                         ( "Duplicate signature algorithms extensions found" ) );
-                    goto error;
+                    MBEDTLS_SSL_PEND_FATAL_ALERT(
+                        MBEDTLS_SSL_ALERT_MSG_DECODE_ERROR,
+                        MBEDTLS_ERR_SSL_DECODE_ERROR );
+                    mbedtls_ssl_handshake_free( ssl );
+                    return( MBEDTLS_ERR_SSL_DECODE_ERROR );
                 }
                 break;
 
@@ -1541,24 +1545,27 @@
     {
         MBEDTLS_SSL_DEBUG_MSG( 1,
             ( "Signature algorithms extension length misaligned" ) );
-        goto error;
+        MBEDTLS_SSL_PEND_FATAL_ALERT( MBEDTLS_SSL_ALERT_MSG_DECODE_ERROR,
+                                      MBEDTLS_ERR_SSL_DECODE_ERROR );
+        mbedtls_ssl_handshake_free( ssl );
+        return( MBEDTLS_ERR_SSL_DECODE_ERROR );
     }
     /* Check that we found signature algorithms extension */
     if( ! sig_alg_ext_found )
     {
-         MBEDTLS_SSL_DEBUG_MSG( 3,
-             ( "no signature algorithms extension found" ) );
-         goto error;
+        MBEDTLS_SSL_DEBUG_MSG( 3,
+            ( "no signature algorithms extension found" ) );
+        MBEDTLS_SSL_DEBUG_MSG( 1,
+            ( "Signature algorithms extension length misaligned" ) );
+        MBEDTLS_SSL_PEND_FATAL_ALERT( MBEDTLS_SSL_ALERT_MSG_DECODE_ERROR,
+                                      MBEDTLS_ERR_SSL_DECODE_ERROR );
+        mbedtls_ssl_handshake_free( ssl );
+        return( MBEDTLS_ERR_SSL_DECODE_ERROR );
+
     }
 
     ssl->client_auth = 1;
     return( 0 );
-
-error:
-    MBEDTLS_SSL_PEND_FATAL_ALERT( MBEDTLS_SSL_ALERT_MSG_DECODE_ERROR,
-                                  MBEDTLS_ERR_SSL_DECODE_ERROR );
-    mbedtls_free( ssl->handshake->certificate_request_context );
-    return( MBEDTLS_ERR_SSL_DECODE_ERROR );
 }
 
 /*