Fix memory leak on failure in test_suite_ssl
diff --git a/tests/suites/test_suite_ssl.function b/tests/suites/test_suite_ssl.function
index 487d3ce..c21b728 100644
--- a/tests/suites/test_suite_ssl.function
+++ b/tests/suites/test_suite_ssl.function
@@ -12,7 +12,9 @@
     do                                          \
     {                                           \
         if( !( x ) )                            \
-            return( 1 );                        \
+        {                                       \
+            goto cleanup;                       \
+        }                                       \
     } while( 0 )
 
 
@@ -24,7 +26,7 @@
     mbedtls_cipher_info_t const *cipher_info;
 
     size_t keylen, maclen, ivlen;
-    unsigned char *key0, *key1;
+    unsigned char *key0 = NULL, *key1 = NULL;
     unsigned char iv_enc[16], iv_dec[16];
 
     maclen = 0;
@@ -70,8 +72,6 @@
                                 keylen << 3, MBEDTLS_ENCRYPT ) == 0 );
     CHK( mbedtls_cipher_setkey( &t_out->cipher_ctx_dec, key0,
                                 keylen << 3, MBEDTLS_DECRYPT ) == 0 );
-    free( key0 );
-    free( key1 );
 
     /* Setup MAC contexts */
 #if defined(MBEDTLS_SSL_SOME_MODES_USE_MAC)
@@ -223,6 +223,11 @@
     memcpy( &t_out->iv_dec, iv_enc, sizeof( iv_enc ) );
     memcpy( &t_out->iv_enc, iv_dec, sizeof( iv_dec ) );
 
+cleanup:
+
+    free( key0 );
+    free( key1 );
+
     return( 0 );
 }
 
@@ -293,7 +298,7 @@
     mbedtls_ssl_context ssl; /* ONLY for debugging */
 
     mbedtls_ssl_transform t0, t1;
-    unsigned char *buf;
+    unsigned char *buf = NULL;
     size_t const buflen = 512;
     mbedtls_record rec, rec_backup;
 
@@ -373,6 +378,8 @@
                              rec.data_len ) == 0 );
     }
 
+exit:
+
     /* Cleanup */
     mbedtls_ssl_free( &ssl );
     mbedtls_ssl_transform_free( &t0 );
@@ -409,7 +416,7 @@
     mbedtls_ssl_context ssl; /* ONLY for debugging */
 
     mbedtls_ssl_transform t0, t1;
-    unsigned char *buf;
+    unsigned char *buf = NULL;
     size_t const buflen = 150;
     mbedtls_record rec, rec_backup;
 
@@ -519,6 +526,8 @@
         TEST_ASSERT( seen_success == 1 );
     }
 
+exit:
+
     /* Cleanup */
     mbedtls_ssl_free( &ssl );
     mbedtls_ssl_transform_free( &t0 );