Add 'exit' label and variable initialization to relevant test suite functions
diff --git a/tests/suites/test_suite_aes.function b/tests/suites/test_suite_aes.function
index 20f5889..3bd7d4a 100644
--- a/tests/suites/test_suite_aes.function
+++ b/tests/suites/test_suite_aes.function
@@ -36,6 +36,7 @@
         TEST_ASSERT( strcmp( (char *) dst_str, hex_dst_string ) == 0 );
     }
 
+exit:
     aes_free( &ctx );
 }
 /* END_CASE */
@@ -69,6 +70,7 @@
         TEST_ASSERT( strcmp( (char *) dst_str, hex_dst_string ) == 0 );
     }
 
+exit:
     aes_free( &ctx );
 }
 /* END_CASE */
@@ -106,6 +108,7 @@
         TEST_ASSERT( strcmp( (char *) dst_str, hex_dst_string ) == 0 );
     }
 
+exit:
     aes_free( &ctx );
 }
 /* END_CASE */
@@ -143,6 +146,7 @@
         TEST_ASSERT( strcmp( (char *) dst_str, hex_dst_string ) == 0 );
     }
 
+exit:
     aes_free( &ctx );
 }
 /* END_CASE */
@@ -177,6 +181,7 @@
 
     TEST_ASSERT( strcmp( (char *) dst_str, hex_dst_string ) == 0 );
 
+exit:
     aes_free( &ctx );
 }
 /* END_CASE */
@@ -211,6 +216,7 @@
 
     TEST_ASSERT( strcmp( (char *) dst_str, hex_dst_string ) == 0 );
 
+exit:
     aes_free( &ctx );
 }
 /* END_CASE */
@@ -244,6 +250,7 @@
 
     TEST_ASSERT( strcmp( (char *) dst_str, hex_dst_string ) == 0 );
 
+exit:
     aes_free( &ctx );
 }
 /* END_CASE */
@@ -277,6 +284,7 @@
 
     TEST_ASSERT( strcmp( (char *) dst_str, hex_dst_string ) == 0 );
 
+exit:
     aes_free( &ctx );
 }
 /* END_CASE */
diff --git a/tests/suites/test_suite_arc4.function b/tests/suites/test_suite_arc4.function
index f55a5e8..b6d3d4c 100644
--- a/tests/suites/test_suite_arc4.function
+++ b/tests/suites/test_suite_arc4.function
@@ -33,6 +33,7 @@
 
     TEST_ASSERT( strcmp( (char *) dst_hexstr, hex_dst_string ) == 0 );
 
+exit:
     arc4_free( &ctx );
 }
 /* END_CASE */
diff --git a/tests/suites/test_suite_base64.function b/tests/suites/test_suite_base64.function
index b8a318f..de39df6 100644
--- a/tests/suites/test_suite_base64.function
+++ b/tests/suites/test_suite_base64.function
@@ -52,7 +52,7 @@
 void base64_encode_hex( char *src_hex, char *dst, int dst_buf_size,
                         int result )
 {
-    unsigned char *src, *res;
+    unsigned char *src = NULL, *res = NULL;
     size_t len = dst_buf_size, src_len;
 
     src = unhexify_alloc( src_hex, &src_len );
@@ -65,6 +65,7 @@
         TEST_ASSERT( memcmp( dst, res, len ) == 0 );
     }
 
+exit:
     polarssl_free( src );
     polarssl_free( res );
 }
@@ -74,7 +75,7 @@
 void base64_decode_hex( char *src, char *dst_hex, int dst_buf_size,
                         int result )
 {
-    unsigned char *dst, *res;
+    unsigned char *dst = NULL, *res = NULL;
     size_t len = dst_buf_size, dst_len;
 
     dst = unhexify_alloc( dst_hex, &dst_len );
@@ -88,6 +89,7 @@
         TEST_ASSERT( memcmp( dst, res, len ) == 0 );
     }
 
+exit:
     polarssl_free( dst );
     polarssl_free( res );
 }
diff --git a/tests/suites/test_suite_blowfish.function b/tests/suites/test_suite_blowfish.function
index 17a5b65..b058698 100644
--- a/tests/suites/test_suite_blowfish.function
+++ b/tests/suites/test_suite_blowfish.function
@@ -36,6 +36,7 @@
         TEST_ASSERT( strcmp( (char *) dst_str, hex_dst_string ) == 0 );
     }
 
+exit:
     blowfish_free( &ctx );
 }
 /* END_CASE */
@@ -69,6 +70,7 @@
         TEST_ASSERT( strcmp( (char *) dst_str, hex_dst_string ) == 0 );
     }
 
+exit:
     blowfish_free( &ctx );
 }
 /* END_CASE */
@@ -107,6 +109,7 @@
         TEST_ASSERT( strcmp( (char *) dst_str, hex_dst_string ) == 0 );
     }
 
+exit:
     blowfish_free( &ctx );
 }
 /* END_CASE */
@@ -144,6 +147,7 @@
         TEST_ASSERT( strcmp( (char *) dst_str, hex_dst_string ) == 0 );
     }
 
+exit:
     blowfish_free( &ctx );
 }
 /* END_CASE */
@@ -178,6 +182,7 @@
 
     TEST_ASSERT( strcmp( (char *) dst_str, hex_dst_string ) == 0 );
 
+exit:
     blowfish_free( &ctx );
 }
 /* END_CASE */
@@ -212,6 +217,7 @@
 
     TEST_ASSERT( strcmp( (char *) dst_str, hex_dst_string ) == 0 );
 
+exit:
     blowfish_free( &ctx );
 }
 /* END_CASE */
@@ -248,6 +254,7 @@
 
     TEST_ASSERT( strcmp( (char *) dst_str, hex_dst_string ) == 0 );
 
+exit:
     blowfish_free( &ctx );
 }
 /* END_CASE */
diff --git a/tests/suites/test_suite_camellia.function b/tests/suites/test_suite_camellia.function
index c5b66a6..6d88f8c 100644
--- a/tests/suites/test_suite_camellia.function
+++ b/tests/suites/test_suite_camellia.function
@@ -36,6 +36,7 @@
         TEST_ASSERT( strcasecmp( (char *) dst_str, hex_dst_string ) == 0 );
     }
 
+exit:
     camellia_free( &ctx );
 }
 /* END_CASE */
@@ -69,6 +70,7 @@
         TEST_ASSERT( strcasecmp( (char *) dst_str, hex_dst_string ) == 0 );
     }
 
+exit:
     camellia_free( &ctx );
 }
 /* END_CASE */
@@ -106,6 +108,7 @@
         TEST_ASSERT( strcasecmp( (char *) dst_str, hex_dst_string ) == 0 );
     }
 
+exit:
     camellia_free( &ctx );
 }
 /* END_CASE */
@@ -143,6 +146,7 @@
         TEST_ASSERT( strcasecmp( (char *) dst_str, hex_dst_string ) == 0 );
     }
 
+exit:
     camellia_free( &ctx );
 }
 /* END_CASE */
@@ -177,6 +181,7 @@
 
     TEST_ASSERT( strcasecmp( (char *) dst_str, hex_dst_string ) == 0 );
 
+exit:
     camellia_free( &ctx );
 }
 /* END_CASE */
@@ -211,6 +216,7 @@
 
     TEST_ASSERT( strcasecmp( (char *) dst_str, hex_dst_string ) == 0 );
 
+exit:
     camellia_free( &ctx );
 }
 /* END_CASE */
diff --git a/tests/suites/test_suite_ccm.function b/tests/suites/test_suite_ccm.function
index 8521fba..d513a15 100644
--- a/tests/suites/test_suite_ccm.function
+++ b/tests/suites/test_suite_ccm.function
@@ -27,6 +27,7 @@
     ret = ccm_init( &ctx, cipher_id, key, key_size );
     TEST_ASSERT( ret == result );
 
+exit:
     ccm_free( &ctx );
 }
 /* END_CASE */
@@ -64,6 +65,7 @@
     else
         TEST_ASSERT( decrypt_ret == res );
 
+exit:
     ccm_free( &ctx );
 }
 /* END_CASE */
@@ -106,6 +108,7 @@
     /* Check we didn't write past the end */
     TEST_ASSERT( msg[result_len] == 0 && msg[result_len + 1] == 0 );
 
+exit:
     ccm_free( &ctx );
 }
 /* END_CASE */
@@ -171,6 +174,7 @@
     /* Check we didn't write past the end (where the original tag is) */
     TEST_ASSERT( memcmp( msg + msg_len, tag, tag_len ) == 0 );
 
+exit:
     ccm_free( &ctx );
 }
 /* END_CASE */
diff --git a/tests/suites/test_suite_cipher.function b/tests/suites/test_suite_cipher.function
index 3afdff6..2bc1ef9 100644
--- a/tests/suites/test_suite_cipher.function
+++ b/tests/suites/test_suite_cipher.function
@@ -207,6 +207,7 @@
     /*
      * Done
      */
+exit:
     cipher_free( &ctx_dec );
     cipher_free( &ctx_enc );
 }
@@ -259,6 +260,7 @@
     TEST_ASSERT( ret == cipher_finish( &ctx, encbuf + outlen, &outlen ) );
 
     /* done */
+exit:
     cipher_free( &ctx );
 }
 /* END_CASE */
@@ -308,6 +310,7 @@
                  &ctx_dec, decbuf + outlen, &outlen ) );
     TEST_ASSERT( 0 == outlen );
 
+exit:
     cipher_free( &ctx_dec );
 }
 /* END_CASE */
@@ -397,6 +400,7 @@
 
     TEST_ASSERT( 0 == memcmp(inbuf, decbuf, length) );
 
+exit:
     cipher_free( &ctx_dec );
     cipher_free( &ctx_enc );
 }
@@ -479,6 +483,7 @@
         TEST_ASSERT( 0 == memcmp( output, clear, clear_len ) );
     }
 
+exit:
     cipher_free( &ctx );
 }
 /* END_CASE */
@@ -536,7 +541,7 @@
     if( strcmp( hex_clear, "FAIL" ) == 0 )
     {
         TEST_ASSERT( ret == POLARSSL_ERR_CIPHER_AUTH_FAILED );
-        goto cleanup;
+        goto exit;
     }
 
     /* otherwise, make sure it was decrypted properly */
@@ -566,7 +571,7 @@
     TEST_ASSERT( my_tag[tag_len + 1] == 0xFF );
 
 
-cleanup:
+exit:
     cipher_free( &ctx );
 }
 /* END_CASE */
@@ -616,6 +621,7 @@
         TEST_ASSERT( 0 == memcmp( output, result,
                                   cipher_get_block_size( &ctx ) ) );
 
+exit:
     cipher_free( &ctx );
 }
 /* END_CASE */
@@ -634,6 +640,7 @@
 
     TEST_ASSERT( ret == cipher_set_padding_mode( &ctx, pad_mode ) );
 
+exit:
     cipher_free( &ctx );
 }
 /* END_CASE */
diff --git a/tests/suites/test_suite_ctr_drbg.function b/tests/suites/test_suite_ctr_drbg.function
index b3790a2..fd9f087 100644
--- a/tests/suites/test_suite_ctr_drbg.function
+++ b/tests/suites/test_suite_ctr_drbg.function
@@ -46,6 +46,7 @@
     hexify( output_str, buf, 16 );
     TEST_ASSERT( strcmp( (char *) output_str, result_str ) == 0 );
 
+exit:
     ctr_drbg_free( &ctx );
 }
 /* END_CASE */
@@ -82,6 +83,7 @@
     hexify( output_str, buf, 16 );
     TEST_ASSERT( strcmp( (char *) output_str, result_str ) == 0 );
 
+exit:
     ctr_drbg_free( &ctx );
 }
 /* END_CASE */
@@ -155,6 +157,7 @@
     TEST_ASSERT( ctr_drbg_random( &ctx, out, sizeof( out ) ) == 0 );
     TEST_ASSERT( test_offset_idx - last_idx == 13 );
 
+exit:
     ctr_drbg_free( &ctx );
 }
 /* END_CASE */
@@ -168,6 +171,7 @@
     TEST_ASSERT( ctr_drbg_write_seed_file( &ctx, path ) == ret );
     TEST_ASSERT( ctr_drbg_update_seed_file( &ctx, path ) == ret );
 
+exit:
     ctr_drbg_free( &ctx );
 }
 /* END_CASE */
diff --git a/tests/suites/test_suite_debug.function b/tests/suites/test_suite_debug.function
index 7717a61..b31b72a 100644
--- a/tests/suites/test_suite_debug.function
+++ b/tests/suites/test_suite_debug.function
@@ -117,6 +117,7 @@
 
     TEST_ASSERT( strcmp( buffer.buf, result_str ) == 0 );
 
+exit:
     x509_crt_free( &crt );
 }
 /* END_CASE */
@@ -144,6 +145,7 @@
 
     TEST_ASSERT( strcmp( buffer.buf, result_str ) == 0 );
 
+exit:
     mpi_free( &val );
 }
 /* END_CASE */
diff --git a/tests/suites/test_suite_des.function b/tests/suites/test_suite_des.function
index 0231757..4b5d53d 100644
--- a/tests/suites/test_suite_des.function
+++ b/tests/suites/test_suite_des.function
@@ -45,6 +45,7 @@
 
     TEST_ASSERT( strcasecmp( (char *) dst_str, hex_dst_string ) == 0 );
 
+exit:
     des_free( &ctx );
 }
 /* END_CASE */
@@ -74,6 +75,7 @@
 
     TEST_ASSERT( strcasecmp( (char *) dst_str, hex_dst_string ) == 0 );
 
+exit:
     des_free( &ctx );
 }
 /* END_CASE */
@@ -110,6 +112,7 @@
         TEST_ASSERT( strcasecmp( (char *) dst_str, hex_dst_string ) == 0 );
     }
 
+exit:
     des_free( &ctx );
 }
 /* END_CASE */
@@ -146,6 +149,7 @@
         TEST_ASSERT( strcasecmp( (char *) dst_str, hex_dst_string ) == 0 );
     }
 
+exit:
     des_free( &ctx );
 }
 /* END_CASE */
@@ -181,6 +185,7 @@
 
     TEST_ASSERT( strcasecmp( (char *) dst_str, hex_dst_string ) == 0 );
 
+exit:
     des3_free( &ctx );
 }
 /* END_CASE */
@@ -216,6 +221,7 @@
 
     TEST_ASSERT( strcasecmp( (char *) dst_str, hex_dst_string ) == 0 );
 
+exit:
     des3_free( &ctx );
 }
 /* END_CASE */
@@ -260,6 +266,7 @@
         TEST_ASSERT( strcasecmp( (char *) dst_str, hex_dst_string ) == 0 );
     }
 
+exit:
     des3_free( &ctx );
 }
 /* END_CASE */
@@ -304,6 +311,7 @@
         TEST_ASSERT( strcasecmp( (char *) dst_str, hex_dst_string ) == 0 );
     }
 
+exit:
     des3_free( &ctx );
 }
 /* END_CASE */
diff --git a/tests/suites/test_suite_dhm.function b/tests/suites/test_suite_dhm.function
index 8c85517..ba9477f 100644
--- a/tests/suites/test_suite_dhm.function
+++ b/tests/suites/test_suite_dhm.function
@@ -92,6 +92,7 @@
     TEST_ASSERT( sec_srv_len != 0 );
     TEST_ASSERT( memcmp( sec_srv, sec_cli, sec_srv_len ) == 0 );
 
+exit:
     dhm_free( &ctx_srv );
     dhm_free( &ctx_cli );
 }
@@ -115,6 +116,7 @@
     TEST_ASSERT( mpi_cmp_mpi( &ctx.P, &P ) == 0 );
     TEST_ASSERT( mpi_cmp_mpi( &ctx.G, &G ) == 0 );
 
+exit:
     mpi_free( &P ); mpi_free( &G );
     dhm_free( &ctx );
 }
diff --git a/tests/suites/test_suite_ecdh.function b/tests/suites/test_suite_ecdh.function
index 4ef8c1d..c84d2b1 100644
--- a/tests/suites/test_suite_ecdh.function
+++ b/tests/suites/test_suite_ecdh.function
@@ -34,6 +34,7 @@
 
     TEST_ASSERT( mpi_cmp_mpi( &zA, &zB ) == 0 );
 
+exit:
     ecp_group_free( &grp );
     ecp_point_free( &qA ); ecp_point_free( &qB );
     mpi_free( &dA ); mpi_free( &dB );
@@ -114,6 +115,7 @@
     TEST_ASSERT( ecdh_compute_shared( &grp, &zB, &qA, &dB, NULL, NULL ) == 0 );
     TEST_ASSERT( mpi_cmp_mpi( &zB, &check ) == 0 );
 
+exit:
     ecp_group_free( &grp );
     ecp_point_free( &qA ); ecp_point_free( &qB );
     mpi_free( &dA ); mpi_free( &dB );
@@ -151,6 +153,7 @@
     TEST_ASSERT( ecdh_calc_secret( &cli, &len, buf, 1000, NULL, NULL ) == 0 );
     TEST_ASSERT( mpi_cmp_mpi( &srv.z, &cli.z ) == 0 );
 
+exit:
     ecdh_free( &srv );
     ecdh_free( &cli );
 }
diff --git a/tests/suites/test_suite_ecdsa.function b/tests/suites/test_suite_ecdsa.function
index 10fb66b..144326b 100644
--- a/tests/suites/test_suite_ecdsa.function
+++ b/tests/suites/test_suite_ecdsa.function
@@ -32,6 +32,7 @@
                              &rnd_pseudo_rand, &rnd_info ) == 0 );
     TEST_ASSERT( ecdsa_verify( &grp, buf, sizeof( buf ), &Q, &r, &s ) == 0 );
 
+exit:
     ecp_group_free( &grp );
     ecp_point_free( &Q );
     mpi_free( &d ); mpi_free( &r ); mpi_free( &s );
@@ -86,6 +87,7 @@
 
     TEST_ASSERT( ecdsa_verify( &grp, hash, hlen, &Q, &r_check, &s_check ) == 0 );
 
+exit:
     ecp_group_free( &grp );
     ecp_point_free( &Q );
     mpi_free( &d ); mpi_free( &r ); mpi_free( &s );
@@ -123,6 +125,7 @@
     TEST_ASSERT( mpi_cmp_mpi( &r, &r_check ) == 0 );
     TEST_ASSERT( mpi_cmp_mpi( &s, &s_check ) == 0 );
 
+exit:
     ecp_group_free( &grp );
     mpi_free( &d ); mpi_free( &r ); mpi_free( &s );
     mpi_free( &r_check ); mpi_free( &s_check );
@@ -183,6 +186,7 @@
                  sig, sig_len ) != 0 );
     sig[sig_len - 1]--;
 
+exit:
     ecdsa_free( &ctx );
 }
 /* END_CASE */
@@ -215,6 +219,7 @@
     TEST_ASSERT( ecdsa_read_signature( &ctx, hash, sizeof( hash ),
                  sig, sig_len ) == 0 );
 
+exit:
     ecdsa_free( &ctx );
 }
 /* END_CASE */
diff --git a/tests/suites/test_suite_ecp.function b/tests/suites/test_suite_ecp.function
index 1e8e31a..62dc606 100644
--- a/tests/suites/test_suite_ecp.function
+++ b/tests/suites/test_suite_ecp.function
@@ -71,6 +71,7 @@
         TEST_ASSERT( mpi_cmp_int( &C.Y, y_c ) == 0 );
     }
 
+exit:
     ecp_group_free( &grp );
     ecp_point_free( &A ); ecp_point_free( &B ); ecp_point_free( &C );
 }
@@ -109,6 +110,7 @@
         TEST_ASSERT( mpi_cmp_int( &C.Y, y_c ) == 0 );
     }
 
+exit:
     ecp_group_free( &grp );
     ecp_point_free( &A ); ecp_point_free( &B ); ecp_point_free( &C );
 }
@@ -162,6 +164,7 @@
         }
     }
 
+exit:
     ecp_group_free( &grp );
     ecp_point_free( &R );
     mpi_free( &m );
@@ -186,6 +189,7 @@
 
     TEST_ASSERT( ecp_check_pubkey( &grp, &P ) == ret );
 
+exit:
     ecp_group_free( &grp );
     ecp_point_free( &P );
 }
@@ -207,6 +211,7 @@
 
     TEST_ASSERT( ecp_check_pubkey( &grp, &P ) == ret );
 
+exit:
     ecp_group_free( &grp );
     ecp_point_free( &P );
 }
@@ -260,6 +265,7 @@
     TEST_ASSERT( mpi_cmp_mpi( &R.Y, &yZ ) == 0 );
     TEST_ASSERT( ecp_check_pubkey( &grp, &R ) == 0 );
 
+exit:
     ecp_group_free( &grp ); ecp_point_free( &R );
     mpi_free( &dA ); mpi_free( &xA ); mpi_free( &yA ); mpi_free( &dB );
     mpi_free( &xB ); mpi_free( &yB ); mpi_free( &xZ ); mpi_free( &yZ );
@@ -309,6 +315,7 @@
     TEST_ASSERT( ecp_check_pubkey( &grp, &R ) == 0 );
     TEST_ASSERT( mpi_cmp_mpi( &R.X, &xS ) == 0 );
 
+exit:
     ecp_group_free( &grp ); ecp_point_free( &R );
     mpi_free( &dA ); mpi_free( &xA );
     mpi_free( &dB ); mpi_free( &xB );
@@ -343,6 +350,7 @@
     TEST_ASSERT( mpi_mod_mpi( &N, &N, &grp.P ) == 0 );
     TEST_ASSERT( mpi_cmp_mpi( &N, &R ) == 0 );
 
+exit:
     mpi_free( &N ); mpi_free( &R );
     ecp_group_free( &grp );
 }
@@ -377,6 +385,7 @@
         TEST_ASSERT( strcasecmp( (char *) str, out ) == 0 );
     }
 
+exit:
     ecp_group_free( &grp ); ecp_point_free( &P );
 }
 /* END_CASE */
@@ -413,6 +422,7 @@
         TEST_ASSERT( mpi_cmp_mpi( &P.Z, &Z ) == 0 );
     }
 
+exit:
     ecp_group_free( &grp ); ecp_point_free( &P );
     mpi_free( &X ); mpi_free( &Y ); mpi_free( &Z );
 }
@@ -452,6 +462,7 @@
         TEST_ASSERT( *vbuf == 0x00 );
     }
 
+exit:
     ecp_group_free( &grp ); ecp_point_free( &P );
     mpi_free( &X ); mpi_free( &Y ); mpi_free( &Z );
 }
@@ -503,6 +514,7 @@
     TEST_ASSERT( ecp_is_zero( &pt ) );
     TEST_ASSERT( vbuf == buf + olen );
 
+exit:
     ecp_group_free( &grp );
     ecp_point_free( &pt );
 }
@@ -530,6 +542,7 @@
         TEST_ASSERT( *vbuf == 0x00 );
     }
 
+exit:
     ecp_group_free( &grp );
 }
 /* END_CASE */
@@ -559,6 +572,7 @@
         TEST_ASSERT( grp1.id == grp2.id );
     }
 
+exit:
     ecp_group_free( &grp1 );
     ecp_group_free( &grp2 );
 }
@@ -578,6 +592,7 @@
 
     TEST_ASSERT( ecp_check_privkey( &grp, &d ) == ret );
 
+exit:
     ecp_group_free( &grp );
     mpi_free( &d );
 }
@@ -604,6 +619,7 @@
     TEST_ASSERT( ecp_check_pubkey( &grp, &Q ) == 0 );
     TEST_ASSERT( ecp_check_privkey( &grp, &d ) == 0 );
 
+exit:
     ecp_group_free( &grp );
     ecp_point_free( &Q );
     mpi_free( &d );
@@ -624,6 +640,7 @@
     TEST_ASSERT( ecp_check_pubkey( &key.grp, &key.Q ) == 0 );
     TEST_ASSERT( ecp_check_privkey( &key.grp, &key.d ) == 0 );
 
+exit:
     ecp_keypair_free( &key );
 }
 /* END_CASE */
diff --git a/tests/suites/test_suite_entropy.function b/tests/suites/test_suite_entropy.function
index 844eb96..6d137ad 100644
--- a/tests/suites/test_suite_entropy.function
+++ b/tests/suites/test_suite_entropy.function
@@ -50,6 +50,7 @@
     TEST_ASSERT( entropy_write_seed_file( &ctx, path ) == ret );
     TEST_ASSERT( entropy_update_seed_file( &ctx, path ) == ret );
 
+exit:
     entropy_free( &ctx );
 }
 /* END_CASE */
@@ -72,6 +73,7 @@
     TEST_ASSERT( entropy_add_source( &ctx, entropy_dummy_source, NULL, 16 )
                  == POLARSSL_ERR_ENTROPY_MAX_SOURCES );
 
+exit:
     entropy_free( &ctx );
 }
 /* END_CASE */
@@ -130,6 +132,7 @@
     ((void) path);
 #endif
 
+exit:
     entropy_free( &ctx );
 }
 /* END_CASE */
@@ -159,6 +162,7 @@
         TEST_ASSERT( ret == result );
     }
 
+exit:
     entropy_free( &ctx );
 }
 /* END_CASE */
diff --git a/tests/suites/test_suite_gcm.function b/tests/suites/test_suite_gcm.function
index 3167bdb..c30b755 100644
--- a/tests/suites/test_suite_gcm.function
+++ b/tests/suites/test_suite_gcm.function
@@ -51,6 +51,7 @@
         TEST_ASSERT( strcmp( (char *) tag_str, hex_tag_string ) == 0 );
     }
 
+exit:
     gcm_free( &ctx );
 }
 /* END_CASE */
@@ -106,6 +107,7 @@
         }
     }
 
+exit:
     gcm_free( &ctx );
 }
 /* END_CASE */
diff --git a/tests/suites/test_suite_hmac_drbg.function b/tests/suites/test_suite_hmac_drbg.function
index 7158756..bd45112 100644
--- a/tests/suites/test_suite_hmac_drbg.function
+++ b/tests/suites/test_suite_hmac_drbg.function
@@ -101,6 +101,8 @@
     last_len = entropy.len;
     TEST_ASSERT( hmac_drbg_random( &ctx, out, sizeof( out ) ) == 0 );
     TEST_ASSERT( (int) last_len - entropy.len == 13 );
+
+exit:
     hmac_drbg_free( &ctx );
 }
 /* END_CASE */
@@ -120,6 +122,7 @@
     TEST_ASSERT( hmac_drbg_write_seed_file( &ctx, path ) == ret );
     TEST_ASSERT( hmac_drbg_update_seed_file( &ctx, path ) == ret );
 
+exit:
     hmac_drbg_free( &ctx );
 }
 /* END_CASE */
@@ -147,6 +150,7 @@
     for( i = 0; i < 30; i++ )
         TEST_ASSERT( hmac_drbg_random( &ctx, out, sizeof( out ) ) == 0 );
 
+exit:
     hmac_drbg_free( &ctx );
 }
 /* END_CASE */
@@ -190,6 +194,8 @@
                                             add1, add1_len ) == 0 );
     TEST_ASSERT( hmac_drbg_random_with_add( &ctx, my_output, out_len,
                                             add2, add2_len ) == 0 );
+
+    /* clear for second run */
     hmac_drbg_free( &ctx );
 
     TEST_ASSERT( memcmp( my_output, output, out_len ) == 0 );
@@ -201,10 +207,10 @@
                                             add1, add1_len ) == 0 );
     TEST_ASSERT( hmac_drbg_random_with_add( &ctx, my_output, out_len,
                                             add2, add2_len ) == 0 );
-    hmac_drbg_free( &ctx );
-
     TEST_ASSERT( memcmp( my_output, output, out_len ) == 0 );
 
+exit:
+    hmac_drbg_free( &ctx );
 }
 /* END_CASE */
 
@@ -246,10 +252,11 @@
                                             add2, add2_len ) == 0 );
     TEST_ASSERT( hmac_drbg_random_with_add( &ctx, my_output, out_len,
                                             add3, add3_len ) == 0 );
-    hmac_drbg_free( &ctx );
 
     TEST_ASSERT( memcmp( my_output, output, out_len ) == 0 );
 
+exit:
+    hmac_drbg_free( &ctx );
 }
 /* END_CASE */
 
@@ -289,9 +296,11 @@
                                             add1, add1_len ) == 0 );
     TEST_ASSERT( hmac_drbg_random_with_add( &ctx, my_output, out_len,
                                             add2, add2_len ) == 0 );
-    hmac_drbg_free( &ctx );
 
     TEST_ASSERT( memcmp( my_output, output, out_len ) == 0 );
+
+exit:
+    hmac_drbg_free( &ctx );
 }
 /* END_CASE */
 
diff --git a/tests/suites/test_suite_hmac_shax.function b/tests/suites/test_suite_hmac_shax.function
index 10b376f..54ad02f 100644
--- a/tests/suites/test_suite_hmac_shax.function
+++ b/tests/suites/test_suite_hmac_shax.function
@@ -58,6 +58,7 @@
     hexify( hash_str, output, sizeof  output );
     TEST_ASSERT( strncmp( (char *) hash_str, hex_hash_string, trunc_size * 2 ) == 0 );
 
+exit:
     sha1_free( &ctx );
 }
 /* END_CASE */
@@ -116,6 +117,7 @@
     hexify( hash_str, output, sizeof  output );
     TEST_ASSERT( strncmp( (char *) hash_str, hex_hash_string, trunc_size * 2 ) == 0 );
 
+exit:
     sha256_free( &ctx );
 }
 /* END_CASE */
@@ -174,6 +176,7 @@
     hexify( hash_str, output, sizeof  output );
     TEST_ASSERT( strncmp( (char *) hash_str, hex_hash_string, trunc_size * 2 ) == 0 );
 
+exit:
     sha256_free( &ctx );
 }
 /* END_CASE */
@@ -232,6 +235,7 @@
     hexify( hash_str, output, sizeof  output );
     TEST_ASSERT( strncmp( (char *) hash_str, hex_hash_string, trunc_size * 2 ) == 0 );
 
+exit:
     sha512_free( &ctx );
 }
 /* END_CASE */
@@ -290,6 +294,7 @@
     hexify( hash_str, output, sizeof  output );
     TEST_ASSERT( strncmp( (char *) hash_str, hex_hash_string, trunc_size * 2 ) == 0 );
 
+exit:
     sha512_free( &ctx );
 }
 /* END_CASE */
diff --git a/tests/suites/test_suite_md.function b/tests/suites/test_suite_md.function
index 338f8af..ea92726 100644
--- a/tests/suites/test_suite_md.function
+++ b/tests/suites/test_suite_md.function
@@ -33,6 +33,9 @@
         TEST_ASSERT( md_process( &ctx, buf ) == 0 );
         md_free( &ctx );
     }
+
+exit:
+    md_free( &ctx );
 }
 /* END_CASE */
 
@@ -198,11 +201,13 @@
     TEST_ASSERT ( ctx.md_ctx != NULL );
     TEST_ASSERT ( 0 == md_update( &ctx, src_str, strlen( (char *) src_str ) ) );
     TEST_ASSERT ( 0 == md_finish( &ctx, output ) );
-    md_free( &ctx );
 
     hexify( hash_str, output, md_get_size(md_info) );
 
     TEST_ASSERT( strcmp( (char *) hash_str, hex_hash_string ) == 0 );
+
+exit:
+    md_free( &ctx );
 }
 /* END_CASE */
 
@@ -236,11 +241,13 @@
     TEST_ASSERT ( ctx.md_ctx != NULL );
     TEST_ASSERT ( 0 == md_update( &ctx, src_str, src_len ) );
     TEST_ASSERT ( 0 == md_finish( &ctx, output ) );
-    md_free( &ctx );
 
     hexify( hash_str, output, md_get_size(md_info) );
 
     TEST_ASSERT( strcmp( (char *) hash_str, hex_hash_string ) == 0 );
+
+exit:
+    md_free( &ctx );
 }
 /* END_CASE */
 
@@ -320,10 +327,12 @@
     TEST_ASSERT ( 0 == md_hmac_reset( &ctx ) );
     TEST_ASSERT ( 0 == md_hmac_update( &ctx, src_str, src_len ) );
     TEST_ASSERT ( 0 == md_hmac_finish( &ctx, output ) );
-    md_free( &ctx );
 
     hexify( hash_str, output, md_get_size(md_info) );
     TEST_ASSERT( strncmp( (char *) hash_str, hex_hash_string, trunc_size * 2 ) == 0 );
+
+exit:
+    md_free( &ctx );
 }
 /* END_CASE */
 
diff --git a/tests/suites/test_suite_mdx.function b/tests/suites/test_suite_mdx.function
index 12a5e1b..ecc1b92 100644
--- a/tests/suites/test_suite_mdx.function
+++ b/tests/suites/test_suite_mdx.function
@@ -139,6 +139,7 @@
     hexify( hash_str, output, sizeof  output );
     TEST_ASSERT( strncmp( (char *) hash_str, hex_hash_string, trunc_size * 2 ) == 0 );
 
+exit:
     md2_free( &ctx );
 }
 /* END_CASE */
@@ -197,6 +198,7 @@
     hexify( hash_str, output, sizeof  output );
     TEST_ASSERT( strncmp( (char *) hash_str, hex_hash_string, trunc_size * 2 ) == 0 );
 
+exit:
     md4_free( &ctx );
 }
 /* END_CASE */
@@ -255,6 +257,7 @@
     hexify( hash_str, output, sizeof  output );
     TEST_ASSERT( strncmp( (char *) hash_str, hex_hash_string, trunc_size * 2 ) == 0 );
 
+exit:
     md5_free( &ctx );
 }
 /* END_CASE */
@@ -313,6 +316,7 @@
     hexify( hash_str, output, sizeof  output );
     TEST_ASSERT( strncmp( (char *) hash_str, hex_hash_string, trunc_size * 2 ) == 0 );
 
+exit:
     ripemd160_free( &ctx );
 }
 /* END_CASE */
diff --git a/tests/suites/test_suite_mpi.function b/tests/suites/test_suite_mpi.function
index ec9752c..2835acb 100644
--- a/tests/suites/test_suite_mpi.function
+++ b/tests/suites/test_suite_mpi.function
@@ -28,6 +28,7 @@
         }
     }
 
+exit:
     mpi_free( &X );
 }
 /* END_CASE */
@@ -49,6 +50,7 @@
     TEST_ASSERT( mpi_write_string( &X, radix_A, (char *) str, &len ) == 0 );
     TEST_ASSERT( strcmp( (char *) str, input_A ) == 0 );
 
+exit:
     mpi_free( &X );
 }
 /* END_CASE */
@@ -81,6 +83,7 @@
         TEST_ASSERT( strcasecmp( (char *) str, input_A ) == 0 );
     }
 
+exit:
     mpi_free( &X );
 }
 /* END_CASE */
@@ -115,6 +118,7 @@
         TEST_ASSERT( strcasecmp( (char *) str, input_A ) == 0 );
     }
 
+exit:
     mpi_free( &X );
 }
 /* END_CASE */
@@ -142,6 +146,7 @@
 
     TEST_ASSERT( mpi_cmp_mpi( &X, &Y ) == 0 );
 
+exit:
     mpi_free( &X ); mpi_free( &Y );
 }
 /* END_CASE */
@@ -154,6 +159,7 @@
     TEST_ASSERT( mpi_read_string( &X, radix_X, input_X ) == 0 );
     TEST_ASSERT( mpi_get_bit( &X, pos ) == val );
 
+exit:
     mpi_free( &X );
 }
 /* END_CASE */
@@ -170,6 +176,7 @@
     TEST_ASSERT( mpi_set_bit( &X, pos, val ) == 0 );
     TEST_ASSERT( mpi_cmp_mpi( &X, &Y ) == 0 );
 
+exit:
     mpi_free( &X ); mpi_free( &Y );
 }
 /* END_CASE */
@@ -183,6 +190,7 @@
     TEST_ASSERT( mpi_read_string( &X, radix_X, input_X ) == 0 );
     TEST_ASSERT( mpi_lsb( &X ) == (size_t) nr_bits );
 
+exit:
     mpi_free( &X );
 }
 /* END_CASE */
@@ -196,6 +204,7 @@
     TEST_ASSERT( mpi_read_string( &X, radix_X, input_X ) == 0 );
     TEST_ASSERT( mpi_msb( &X ) == (size_t) nr_bits );
 
+exit:
     mpi_free( &X );
 }
 /* END_CASE */
@@ -213,6 +222,7 @@
     TEST_ASSERT( mpi_gcd( &Z, &X, &Y ) == 0 );
     TEST_ASSERT( mpi_cmp_mpi( &Z, &A ) == 0 );
 
+exit:
     mpi_free( &A ); mpi_free( &X ); mpi_free( &Y ); mpi_free( &Z );
 }
 /* END_CASE */
@@ -226,6 +236,7 @@
     TEST_ASSERT( mpi_lset( &X, input_X ) == 0);
     TEST_ASSERT( mpi_cmp_int( &X, input_A ) == result_CMP);
 
+exit:
     mpi_free( &X );
 }
 /* END_CASE */
@@ -241,6 +252,7 @@
     TEST_ASSERT( mpi_read_string( &Y, radix_Y, input_Y ) == 0 );
     TEST_ASSERT( mpi_cmp_mpi( &X, &Y ) == input_A );
 
+exit:
     mpi_free( &X ); mpi_free( &Y );
 }
 /* END_CASE */
@@ -256,6 +268,7 @@
     TEST_ASSERT( mpi_read_string( &Y, radix_Y, input_Y ) == 0 );
     TEST_ASSERT( mpi_cmp_abs( &X, &Y ) == input_A );
 
+exit:
     mpi_free( &X ); mpi_free( &Y );
 }
 /* END_CASE */
@@ -275,6 +288,7 @@
     TEST_ASSERT( mpi_cmp_mpi( &X, &Y ) == 0 );
     TEST_ASSERT( mpi_cmp_mpi( &Y, &A ) != 0 );
 
+exit:
     mpi_free( &X ); mpi_free( &Y ); mpi_free( &A );
 }
 /* END_CASE */
@@ -289,6 +303,7 @@
     TEST_ASSERT( mpi_copy( &X, &X ) == 0 );
     TEST_ASSERT( mpi_cmp_int( &X, input_X ) == 0 );
 
+exit:
     mpi_free( &X );
 }
 /* END_CASE */
@@ -305,6 +320,7 @@
     TEST_ASSERT( mpi_shrink( &X, min ) == 0 );
     TEST_ASSERT( X.n == (size_t) after );
 
+exit:
     mpi_free( &X );
 }
 /* END_CASE */
@@ -328,6 +344,7 @@
     TEST_ASSERT( mpi_safe_cond_assign( &X, &Y, 1 ) == 0 );
     TEST_ASSERT( mpi_cmp_mpi( &X, &Y ) == 0 );
 
+exit:
     mpi_free( &X ); mpi_free( &Y ); mpi_free( &XX );
 }
 /* END_CASE */
@@ -357,6 +374,7 @@
     TEST_ASSERT( mpi_cmp_mpi( &Y, &XX ) == 0 );
     TEST_ASSERT( mpi_cmp_mpi( &X, &YY ) == 0 );
 
+exit:
     mpi_free( &X ); mpi_free( &Y );
     mpi_free( &XX ); mpi_free( &YY );
 }
@@ -377,6 +395,7 @@
     TEST_ASSERT( mpi_cmp_mpi( &X, &Y ) != 0 );
     TEST_ASSERT( mpi_cmp_mpi( &Y, &A ) == 0 );
 
+exit:
     mpi_free( &X ); mpi_free( &Y ); mpi_free( &A );
 }
 /* END_CASE */
@@ -394,6 +413,7 @@
     TEST_ASSERT( mpi_add_mpi( &Z, &X, &Y ) == 0 );
     TEST_ASSERT( mpi_cmp_mpi( &Z, &A ) == 0 );
 
+exit:
     mpi_free( &X ); mpi_free( &Y ); mpi_free( &Z ); mpi_free( &A );
 }
 /* END_CASE */
@@ -411,6 +431,7 @@
     TEST_ASSERT( mpi_add_abs( &Z, &X, &Y ) == 0 );
     TEST_ASSERT( mpi_cmp_mpi( &Z, &A ) == 0 );
 
+exit:
     mpi_free( &X ); mpi_free( &Y ); mpi_free( &Z ); mpi_free( &A );
 }
 /* END_CASE */
@@ -428,6 +449,7 @@
     TEST_ASSERT( mpi_add_abs( &X, &X, &Y ) == 0 );
     TEST_ASSERT( mpi_cmp_mpi( &X, &A ) == 0 );
 
+exit:
     mpi_free( &X ); mpi_free( &Y ); mpi_free( &A );
 }
 /* END_CASE */
@@ -445,6 +467,7 @@
     TEST_ASSERT( mpi_add_abs( &Y, &X, &Y ) == 0 );
     TEST_ASSERT( mpi_cmp_mpi( &Y, &A ) == 0 );
 
+exit:
     mpi_free( &X ); mpi_free( &Y ); mpi_free( &A );
 }
 /* END_CASE */
@@ -461,6 +484,7 @@
     TEST_ASSERT( mpi_add_int( &Z, &X, input_Y ) == 0 );
     TEST_ASSERT( mpi_cmp_mpi( &Z, &A ) == 0 );
 
+exit:
     mpi_free( &X ); mpi_free( &Z ); mpi_free( &A );
 }
 /* END_CASE */
@@ -478,6 +502,7 @@
     TEST_ASSERT( mpi_sub_mpi( &Z, &X, &Y ) == 0 );
     TEST_ASSERT( mpi_cmp_mpi( &Z, &A ) == 0 );
 
+exit:
     mpi_free( &X ); mpi_free( &Y ); mpi_free( &Z ); mpi_free( &A );
 }
 /* END_CASE */
@@ -499,6 +524,7 @@
     if( res == 0 )
         TEST_ASSERT( mpi_cmp_mpi( &Z, &A ) == 0 );
 
+exit:
     mpi_free( &X ); mpi_free( &Y ); mpi_free( &Z ); mpi_free( &A );
 }
 /* END_CASE */
@@ -515,6 +541,7 @@
     TEST_ASSERT( mpi_sub_int( &Z, &X, input_Y ) == 0 );
     TEST_ASSERT( mpi_cmp_mpi( &Z, &A ) == 0 );
 
+exit:
     mpi_free( &X ); mpi_free( &Z ); mpi_free( &A );
 }
 /* END_CASE */
@@ -532,6 +559,7 @@
     TEST_ASSERT( mpi_mul_mpi( &Z, &X, &Y ) == 0 );
     TEST_ASSERT( mpi_cmp_mpi( &Z, &A ) == 0 );
 
+exit:
     mpi_free( &X ); mpi_free( &Y ); mpi_free( &Z ); mpi_free( &A );
 }
 /* END_CASE */
@@ -553,6 +581,7 @@
     else
         TEST_ASSERT( "unknown operator" == 0 );
 
+exit:
     mpi_free( &X ); mpi_free( &Z ); mpi_free( &A );
 }
 /* END_CASE */
@@ -579,6 +608,7 @@
         TEST_ASSERT( mpi_cmp_mpi( &R, &B ) == 0 );
     }
 
+exit:
     mpi_free( &X ); mpi_free( &Y ); mpi_free( &Q ); mpi_free( &R );
     mpi_free( &A ); mpi_free( &B );
 }
@@ -604,6 +634,7 @@
         TEST_ASSERT( mpi_cmp_mpi( &R, &B ) == 0 );
     }
 
+exit:
     mpi_free( &X ); mpi_free( &Q ); mpi_free( &R ); mpi_free( &A );
     mpi_free( &B );
 }
@@ -627,6 +658,7 @@
         TEST_ASSERT( mpi_cmp_mpi( &X, &A ) == 0 );
     }
 
+exit:
     mpi_free( &X ); mpi_free( &Y ); mpi_free( &A );
 }
 /* END_CASE */
@@ -648,6 +680,7 @@
         TEST_ASSERT( r == (t_uint) input_A );
     }
 
+exit:
     mpi_free( &X );
 }
 /* END_CASE */
@@ -677,6 +710,7 @@
         TEST_ASSERT( mpi_cmp_mpi( &Z, &X ) == 0 );
     }
 
+exit:
     mpi_free( &A  ); mpi_free( &E ); mpi_free( &N );
     mpi_free( &RR ); mpi_free( &Z ); mpi_free( &X );
 }
@@ -700,6 +734,7 @@
         TEST_ASSERT( mpi_cmp_mpi( &Z, &A ) == 0 );
     }
 
+exit:
     mpi_free( &X ); mpi_free( &Y ); mpi_free( &Z ); mpi_free( &A );
 }
 /* END_CASE */
@@ -715,6 +750,7 @@
     res = mpi_is_prime( &X, rnd_std_rand, NULL );
     TEST_ASSERT( res == div_result );
 
+exit:
     mpi_free( &X );
 }
 /* END_CASE */
@@ -745,6 +781,7 @@
         }
     }
 
+exit:
     mpi_free( &X );
 }
 /* END_CASE */
@@ -761,6 +798,7 @@
     TEST_ASSERT( mpi_shift_l( &X, shift_X ) == 0 );
     TEST_ASSERT( mpi_cmp_mpi( &X, &A ) == 0 );
 
+exit:
     mpi_free( &X ); mpi_free( &A );
 }
 /* END_CASE */
@@ -777,6 +815,7 @@
     TEST_ASSERT( mpi_shift_r( &X, shift_X ) == 0 );
     TEST_ASSERT( mpi_cmp_mpi( &X, &A ) == 0 );
 
+exit:
     mpi_free( &X ); mpi_free( &A );
 }
 /* END_CASE */
diff --git a/tests/suites/test_suite_pbkdf2.function b/tests/suites/test_suite_pbkdf2.function
index 4b31896..cbac80e 100644
--- a/tests/suites/test_suite_pbkdf2.function
+++ b/tests/suites/test_suite_pbkdf2.function
@@ -38,9 +38,11 @@
     TEST_ASSERT( md_init_ctx( &ctx, info ) == 0 );
     TEST_ASSERT( pbkdf2_hmac( &ctx, pw_str, pw_len, salt_str, salt_len,
                               it_cnt, key_len, key ) == 0 );
-    md_free( &ctx );
 
     hexify( dst_str, key, key_len );
     TEST_ASSERT( strcmp( (char *) dst_str, result_key_string ) == 0 );
+
+exit:
+    md_free( &ctx );
 }
 /* END_CASE */
diff --git a/tests/suites/test_suite_pem.function b/tests/suites/test_suite_pem.function
index 42d9779..e8b05eb 100644
--- a/tests/suites/test_suite_pem.function
+++ b/tests/suites/test_suite_pem.function
@@ -12,7 +12,7 @@
 void pem_write_buffer( char *start, char *end, char *buf_str, char *result_str )
 {
     unsigned char buf[5000];
-    unsigned char *check_buf;
+    unsigned char *check_buf = NULL;
     int ret;
     size_t buf_len, olen = 0, olen2 = 0;
 
@@ -33,6 +33,8 @@
     TEST_ASSERT( olen > strlen( (char*) result_str ) );
     TEST_ASSERT( ret == 0 );
     TEST_ASSERT( strncmp( (char *) check_buf, (char *) result_str, olen ) == 0 );
+
+exit:
     polarssl_free( check_buf );
 }
 /* END_CASE */
diff --git a/tests/suites/test_suite_pk.function b/tests/suites/test_suite_pk.function
index 3da1feb..dc7dee9 100644
--- a/tests/suites/test_suite_pk.function
+++ b/tests/suites/test_suite_pk.function
@@ -75,6 +75,7 @@
     TEST_ASSERT( pk_get_len( &pk ) == (unsigned) len );
     TEST_ASSERT( strcmp( pk_get_name( &pk), name ) == 0 );
 
+exit:
     pk_free( &pk );
 }
 /* END_CASE */
@@ -113,6 +114,7 @@
     TEST_ASSERT( pk_verify( &pk, digest, hash_result, 0,
                             result_str, pk_get_len( &pk ) ) == result );
 
+exit:
     pk_free( &pk );
 }
 /* END_CASE */
@@ -178,6 +180,7 @@
                                 digest, hash_result, hash_len,
                                 result_str, pk_get_len( &pk ) ) == result );
 
+exit:
     pk_free( &pk );
 }
 /* END_CASE */
@@ -209,6 +212,7 @@
     TEST_ASSERT( pk_verify( &pk, POLARSSL_MD_NONE,
                             hash, hash_len, sig, sig_len ) == ret );
 
+exit:
     pk_free( &pk );
 }
 /* END_CASE */
@@ -234,6 +238,7 @@
     TEST_ASSERT( pk_verify( &pk, POLARSSL_MD_NONE,
                             hash, sizeof hash, sig, sig_len ) == verify_ret );
 
+exit:
     pk_free( &pk );
 }
 /* END_CASE */
@@ -274,6 +279,7 @@
     TEST_ASSERT( olen == res_len );
     TEST_ASSERT( memcmp( output, result, olen ) == 0 );
 
+exit:
     pk_free( &pk );
 }
 /* END_CASE */
@@ -338,6 +344,7 @@
         TEST_ASSERT( memcmp( output, clear, olen ) == 0 );
     }
 
+exit:
     mpi_free( &P1 ); mpi_free( &Q1 ); mpi_free( &H ); mpi_free( &G );
     pk_free( &pk );
 }
@@ -369,6 +376,7 @@
                              output, &olen, sizeof( output ),
                              rnd_pseudo_rand, &rnd_info ) == ret );
 
+exit:
     pk_free( &pk );
 }
 /* END_CASE */
@@ -442,6 +450,7 @@
                             hash, sizeof hash, sig, sig_len ) == ret );
     TEST_ASSERT( pk_debug( &alt, dbg_items ) == ret );
 
+exit:
     rsa_free( &raw );
     pk_free( &rsa ); pk_free( &alt );
 }
diff --git a/tests/suites/test_suite_pkcs1_v21.function b/tests/suites/test_suite_pkcs1_v21.function
index e1dfc52..24b200e 100644
--- a/tests/suites/test_suite_pkcs1_v21.function
+++ b/tests/suites/test_suite_pkcs1_v21.function
@@ -46,6 +46,7 @@
         TEST_ASSERT( strcasecmp( (char *) output_str, result_hex_str ) == 0 );
     }
 
+exit:
     rsa_free( &ctx );
 }
 /* END_CASE */
@@ -101,6 +102,7 @@
         TEST_ASSERT( strncasecmp( (char *) output_str, result_hex_str, strlen( result_hex_str ) ) == 0 );
     }
 
+exit:
     mpi_free( &P1 ); mpi_free( &Q1 ); mpi_free( &H ); mpi_free( &G );
     rsa_free( &ctx );
 }
@@ -164,6 +166,7 @@
         TEST_ASSERT( strcasecmp( (char *) output_str, result_hex_str ) == 0 );
     }
 
+exit:
     mpi_free( &P1 ); mpi_free( &Q1 ); mpi_free( &H ); mpi_free( &G );
     rsa_free( &ctx );
 }
@@ -201,6 +204,7 @@
 
     TEST_ASSERT( rsa_pkcs1_verify( &ctx, NULL, NULL, RSA_PUBLIC, digest, 0, hash_result, result_str ) == result );
 
+exit:
     rsa_free( &ctx );
 }
 /* END_CASE */
@@ -257,6 +261,7 @@
                                         mgf_hash, salt_len,
                                         result_str ) == result_full );
 
+exit:
     rsa_free( &ctx );
 }
 /* END_CASE */
diff --git a/tests/suites/test_suite_pkcs5.function b/tests/suites/test_suite_pkcs5.function
index a86778a..1f61db6 100644
--- a/tests/suites/test_suite_pkcs5.function
+++ b/tests/suites/test_suite_pkcs5.function
@@ -39,10 +39,12 @@
     TEST_ASSERT( md_init_ctx( &ctx, info ) == 0 );
     TEST_ASSERT( pkcs5_pbkdf2_hmac( &ctx, pw_str, pw_len, salt_str, salt_len,
                                      it_cnt, key_len, key ) == 0 );
-    md_free( &ctx );
 
     hexify( dst_str, key, key_len );
     TEST_ASSERT( strcmp( (char *) dst_str, result_key_string ) == 0 );
+
+exit:
+    md_free( &ctx );
 }
 /* END_CASE */
 
@@ -52,7 +54,7 @@
 {
     int my_ret;
     asn1_buf params;
-    unsigned char *my_out, *ref_out, *data, *pw;
+    unsigned char *my_out = NULL, *ref_out = NULL, *data = NULL, *pw = NULL;
     size_t ref_out_len, data_len, pw_len;
 
     params.tag = params_tag;
@@ -70,6 +72,7 @@
     if( ref_ret == 0 )
         TEST_ASSERT( memcmp( my_out, ref_out, ref_out_len ) == 0 );
 
+exit:
     polarssl_free( params.p );
     polarssl_free( data );
     polarssl_free( pw );
diff --git a/tests/suites/test_suite_pkparse.function b/tests/suites/test_suite_pkparse.function
index 739253d..c074326 100644
--- a/tests/suites/test_suite_pkparse.function
+++ b/tests/suites/test_suite_pkparse.function
@@ -33,6 +33,7 @@
         TEST_ASSERT( rsa_check_privkey( rsa ) == 0 );
     }
 
+exit:
     pk_free( &ctx );
 }
 /* END_CASE */
@@ -57,6 +58,7 @@
         TEST_ASSERT( rsa_check_pubkey( rsa ) == 0 );
     }
 
+exit:
     pk_free( &ctx );
 }
 /* END_CASE */
@@ -81,6 +83,7 @@
         TEST_ASSERT( ecp_check_pubkey( &eckey->grp, &eckey->Q ) == 0 );
     }
 
+exit:
     pk_free( &ctx );
 }
 /* END_CASE */
@@ -105,6 +108,7 @@
         TEST_ASSERT( ecp_check_privkey( &eckey->grp, &eckey->d ) == 0 );
     }
 
+exit:
     pk_free( &ctx );
 }
 /* END_CASE */
@@ -131,6 +135,7 @@
         TEST_ASSERT( 1 );
     }
 
+exit:
     pk_free( &pk );
 }
 /* END_CASE */
diff --git a/tests/suites/test_suite_pkwrite.function b/tests/suites/test_suite_pkwrite.function
index e172315..b6cb943 100644
--- a/tests/suites/test_suite_pkwrite.function
+++ b/tests/suites/test_suite_pkwrite.function
@@ -36,6 +36,7 @@
     TEST_ASSERT( ilen == strlen( (char *) buf ) );
     TEST_ASSERT( strncmp( (char *) buf, (char *) check_buf, sizeof( buf ) ) == 0 );
 
+exit:
     pk_free( &key );
 }
 /* END_CASE */
@@ -67,6 +68,7 @@
     TEST_ASSERT( ilen == strlen( (char *) buf ) );
     TEST_ASSERT( strncmp( (char *) buf, (char *) check_buf, sizeof( buf ) ) == 0 );
 
+exit:
     pk_free( &key );
 }
 /* END_CASE */
diff --git a/tests/suites/test_suite_rsa.function b/tests/suites/test_suite_rsa.function
index a762e04..9b3d05a 100644
--- a/tests/suites/test_suite_rsa.function
+++ b/tests/suites/test_suite_rsa.function
@@ -69,6 +69,7 @@
         TEST_ASSERT( strcasecmp( (char *) output_str, result_hex_str ) == 0 );
     }
 
+exit:
     mpi_free( &P1 ); mpi_free( &Q1 ); mpi_free( &H ); mpi_free( &G );
     rsa_free( &ctx );
 }
@@ -104,6 +105,7 @@
 
     TEST_ASSERT( rsa_pkcs1_verify( &ctx, NULL, NULL, RSA_PUBLIC, digest, 0, hash_result, result_str ) == result );
 
+exit:
     rsa_free( &ctx );
 }
 /* END_CASE */
@@ -175,6 +177,7 @@
         TEST_ASSERT( strcasecmp( (char *) output_str, result_hex_str ) == 0 );
     }
 
+exit:
     mpi_free( &P1 ); mpi_free( &Q1 ); mpi_free( &H ); mpi_free( &G );
     rsa_free( &ctx );
 }
@@ -227,6 +230,7 @@
             TEST_ASSERT( ok == 0 );
     }
 
+exit:
     rsa_free( &ctx );
 }
 /* END_CASE */
@@ -266,6 +270,7 @@
         TEST_ASSERT( strcasecmp( (char *) output_str, result_hex_str ) == 0 );
     }
 
+exit:
     rsa_free( &ctx );
 }
 /* END_CASE */
@@ -303,6 +308,7 @@
         TEST_ASSERT( strcasecmp( (char *) output_str, result_hex_str ) == 0 );
     }
 
+exit:
     rsa_free( &ctx );
 }
 /* END_CASE */
@@ -357,6 +363,7 @@
         TEST_ASSERT( strncasecmp( (char *) output_str, result_hex_str, strlen( result_hex_str ) ) == 0 );
     }
 
+exit:
     mpi_free( &P1 ); mpi_free( &Q1 ); mpi_free( &H ); mpi_free( &G );
     rsa_free( &ctx );
 }
@@ -395,6 +402,7 @@
 
     /* And now with the copy */
     TEST_ASSERT( rsa_copy( &ctx2, &ctx ) == 0 );
+    /* clear the original to be sure */
     rsa_free( &ctx );
 
     TEST_ASSERT( rsa_check_pubkey( &ctx2 ) == 0 );
@@ -409,6 +417,8 @@
         TEST_ASSERT( strcasecmp( (char *) output_str, result_hex_str ) == 0 );
     }
 
+exit:
+    rsa_free( &ctx );
     rsa_free( &ctx2 );
 }
 /* END_CASE */
@@ -470,6 +480,7 @@
 
     /* And now one more time with the copy */
     TEST_ASSERT( rsa_copy( &ctx2, &ctx ) == 0 );
+    /* clear the original to be sure */
     rsa_free( &ctx );
 
     TEST_ASSERT( rsa_check_privkey( &ctx2 ) == 0 );
@@ -486,8 +497,9 @@
                                           result_hex_str ) == 0 );
     }
 
+exit:
     mpi_free( &P1 ); mpi_free( &Q1 ); mpi_free( &H ); mpi_free( &G );
-    rsa_free( &ctx2 );
+    rsa_free( &ctx ); rsa_free( &ctx2 );
 }
 /* END_CASE */
 
@@ -520,6 +532,7 @@
 
     TEST_ASSERT( rsa_check_pubkey( &ctx ) == result );
 
+exit:
     rsa_free( &ctx );
 }
 /* END_CASE */
@@ -572,6 +585,7 @@
 
     TEST_ASSERT( rsa_check_privkey( &ctx ) == result );
 
+exit:
     rsa_free( &ctx );
 }
 /* END_CASE */
@@ -596,6 +610,7 @@
         TEST_ASSERT( rsa_check_privkey( &ctx ) == 0 );
     }
 
+exit:
     rsa_free( &ctx );
     ctr_drbg_free( &ctr_drbg );
     entropy_free( &entropy );
diff --git a/tests/suites/test_suite_x509parse.function b/tests/suites/test_suite_x509parse.function
index 52d748f..26b0f70 100644
--- a/tests/suites/test_suite_x509parse.function
+++ b/tests/suites/test_suite_x509parse.function
@@ -45,12 +45,13 @@
     TEST_ASSERT( x509_crt_parse_file( &crt, crt_file ) == 0 );
     res = x509_crt_info( buf, 2000, "", &crt );
 
-    x509_crt_free( &crt );
-
     TEST_ASSERT( res != -1 );
     TEST_ASSERT( res != -2 );
 
     TEST_ASSERT( strcmp( buf, result_str ) == 0 );
+
+exit:
+    x509_crt_free( &crt );
 }
 /* END_CASE */
 
@@ -67,12 +68,13 @@
     TEST_ASSERT( x509_crl_parse_file( &crl, crl_file ) == 0 );
     res = x509_crl_info( buf, 2000, "", &crl );
 
-    x509_crl_free( &crl );
-
     TEST_ASSERT( res != -1 );
     TEST_ASSERT( res != -2 );
 
     TEST_ASSERT( strcmp( buf, result_str ) == 0 );
+
+exit:
+    x509_crl_free( &crl );
 }
 /* END_CASE */
 
@@ -89,12 +91,13 @@
     TEST_ASSERT( x509_csr_parse_file( &csr, csr_file ) == 0 );
     res = x509_csr_info( buf, 2000, "", &csr );
 
-    x509_csr_free( &csr );
-
     TEST_ASSERT( res != -1 );
     TEST_ASSERT( res != -2 );
 
     TEST_ASSERT( strcmp( buf, result_str ) == 0 );
+
+exit:
+    x509_csr_free( &csr );
 }
 /* END_CASE */
 
@@ -133,12 +136,13 @@
 
     res = x509_crt_verify( &crt, &ca, &crl, cn_name, &flags, f_vrfy, NULL );
 
+    TEST_ASSERT( res == ( result ) );
+    TEST_ASSERT( flags == ( flags_result ) );
+
+exit:
     x509_crt_free( &crt );
     x509_crt_free( &ca );
     x509_crl_free( &crl );
-
-    TEST_ASSERT( res == ( result ) );
-    TEST_ASSERT( flags == ( flags_result ) );
 }
 /* END_CASE */
 
@@ -160,12 +164,13 @@
     else
         TEST_ASSERT( "Unknown entity" == 0 );
 
-    x509_crt_free( &crt );
-
     TEST_ASSERT( res != -1 );
     TEST_ASSERT( res != -2 );
 
     TEST_ASSERT( strcmp( buf, result_str ) == 0 );
+
+exit:
+    x509_crt_free( &crt );
 }
 /* END_CASE */
 
@@ -185,6 +190,7 @@
     else
         TEST_ASSERT( "Unknown entity" == 0 );
 
+exit:
     x509_crt_free( &crt );
 }
 /* END_CASE */
@@ -205,6 +211,7 @@
     else
         TEST_ASSERT( "Unknown entity" == 0 );
 
+exit:
     x509_crt_free( &crt );
 }
 /* END_CASE */
@@ -234,6 +241,7 @@
         TEST_ASSERT( strcmp( (char *) output, result_str ) == 0 );
     }
 
+exit:
     x509_crt_free( &crt );
 }
 /* END_CASE */
@@ -263,6 +271,7 @@
         TEST_ASSERT( strcmp( (char *) output, result_str ) == 0 );
     }
 
+exit:
     x509_crl_free( &crl );
 }
 /* END_CASE */
@@ -271,7 +280,7 @@
 void x509_csr_parse( char *csr_der_hex, char *ref_out, int ref_ret )
 {
     x509_csr csr;
-    unsigned char *csr_der;
+    unsigned char *csr_der = NULL;
     char my_out[1000];
     size_t csr_der_len;
     int my_ret;
@@ -290,6 +299,7 @@
         TEST_ASSERT( strcmp( my_out, ref_out ) == 0 );
     }
 
+exit:
     x509_csr_free( &csr );
     polarssl_free( csr_der );
 }
@@ -312,6 +322,7 @@
 
     TEST_ASSERT( i == nb_crt );
 
+exit:
     x509_crt_free( &chain );
 }
 /* END_CASE */
@@ -378,6 +389,7 @@
 
     TEST_ASSERT( x509_crt_check_key_usage( &crt, usage ) == ret );
 
+exit:
     x509_crt_free( &crt );
 }
 /* END_CASE */
@@ -397,6 +409,7 @@
 
     TEST_ASSERT( x509_crt_check_extended_key_usage( &crt, oid, len ) == ret );
 
+exit:
     x509_crt_free( &crt );
 }
 /* END_CASE */
@@ -428,6 +441,7 @@
         TEST_ASSERT( my_salt_len == ref_salt_len );
     }
 
+exit:
     polarssl_free( params.p );
 }
 /* END_CASE */
diff --git a/tests/suites/test_suite_x509write.function b/tests/suites/test_suite_x509write.function
index 2eb270f..340629e 100644
--- a/tests/suites/test_suite_x509write.function
+++ b/tests/suites/test_suite_x509write.function
@@ -52,6 +52,7 @@
     TEST_ASSERT( olen >= pem_len - 1 );
     TEST_ASSERT( memcmp( buf, check_buf, pem_len - 1 ) == 0 );
 
+exit:
     x509write_csr_free( &req );
     pk_free( &key );
 }
@@ -124,6 +125,7 @@
     TEST_ASSERT( olen >= pem_len - 1 );
     TEST_ASSERT( memcmp( buf, check_buf, pem_len - 1 ) == 0 );
 
+exit:
     x509write_crt_free( &crt );
     pk_free( &issuer_key );
     pk_free( &subject_key );