From 6f1eda710ccc8e1e954dd072d4cd074ee804163b Mon Sep 17 00:00:00 2001 From: Paul Elliott Date: Thu, 11 Jun 2020 20:22:00 +0100 Subject: [PATCH] Fix for resource leak in test_suite_ssl Fix for coverity bugs 349041, 349052 Allocated pointers could potentially be leaked in the case of errors. Signed-off-by: Paul Elliott --- tests/suites/test_suite_ssl.function | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/tests/suites/test_suite_ssl.function b/tests/suites/test_suite_ssl.function index 9d16a573b..f9bb52085 100644 --- a/tests/suites/test_suite_ssl.function +++ b/tests/suites/test_suite_ssl.function @@ -1179,6 +1179,7 @@ static int build_transforms( mbedtls_ssl_transform *t_in, size_t keylen, maclen, ivlen; unsigned char *key0 = NULL, *key1 = NULL; + unsigned char *md0 = NULL, *md1 = NULL; unsigned char iv_enc[16], iv_dec[16]; #if defined(MBEDTLS_SSL_DTLS_CONNECTION_ID) @@ -1245,7 +1246,6 @@ static int build_transforms( mbedtls_ssl_transform *t_in, cipher_info->mode == MBEDTLS_MODE_STREAM ) { mbedtls_md_info_t const *md_info; - unsigned char *md0, *md1; /* Pick hash */ md_info = mbedtls_md_info_from_type( hash_id ); @@ -1283,9 +1283,6 @@ static int build_transforms( mbedtls_ssl_transform *t_in, memcpy( &t_out->mac_dec, md0, maclen ); } #endif - - mbedtls_free( md0 ); - mbedtls_free( md1 ); } #else ((void) hash_id); @@ -1417,6 +1414,9 @@ cleanup: mbedtls_free( key0 ); mbedtls_free( key1 ); + mbedtls_free( md0 ); + mbedtls_free( md1 ); + return( ret ); }