diff --git a/programs/ssl/ssl_client2.c b/programs/ssl/ssl_client2.c index 393798138..3cad338b3 100644 --- a/programs/ssl/ssl_client2.c +++ b/programs/ssl/ssl_client2.c @@ -19,6 +19,11 @@ #include "ssl_test_lib.h" +#if defined(MBEDTLS_USE_PSA_CRYPTO) +#define SKIP_LIBRARY_HEADERS +#include "test/psa_crypto_helpers.h" +#endif + #if defined(MBEDTLS_SSL_TEST_IMPOSSIBLE) int main( void ) { @@ -3041,7 +3046,15 @@ exit: #endif #if defined(MBEDTLS_USE_PSA_CRYPTO) + mbedtls_psa_crypto_free( ); + const char* message = mbedtls_test_helper_is_psa_leaking(); + if( message ) + { + if( ret == 0 ) + ret = 1; + mbedtls_printf( "PSA memory leak detected: %s\n", message); + } #endif #if defined(MBEDTLS_TEST_HOOKS) diff --git a/programs/ssl/ssl_server2.c b/programs/ssl/ssl_server2.c index bd4dbb64b..e62a61051 100644 --- a/programs/ssl/ssl_server2.c +++ b/programs/ssl/ssl_server2.c @@ -63,6 +63,11 @@ int main( void ) #include #endif +#if defined(MBEDTLS_USE_PSA_CRYPTO) +#define SKIP_LIBRARY_HEADERS +#include "test/psa_crypto_helpers.h" +#endif + /* Size of memory to be allocated for the heap, when using the library's memory * management and MBEDTLS_MEMORY_BUFFER_ALLOC_C is enabled. */ #define MEMORY_HEAP_SIZE 120000 @@ -4004,6 +4009,13 @@ exit: #if defined(MBEDTLS_USE_PSA_CRYPTO) mbedtls_psa_crypto_free( ); + const char* message = mbedtls_test_helper_is_psa_leaking(); + if( message ) + { + if( ret == 0 ) + ret = 1; + mbedtls_printf( "PSA memory leak detected: %s\n", message); + } #endif #if defined(MBEDTLS_TEST_HOOKS) diff --git a/tests/include/test/psa_crypto_helpers.h b/tests/include/test/psa_crypto_helpers.h index 8a8c37e00..8e7d425a9 100644 --- a/tests/include/test/psa_crypto_helpers.h +++ b/tests/include/test/psa_crypto_helpers.h @@ -28,7 +28,9 @@ #include "test/psa_helpers.h" #include +#if !defined(SKIP_LIBRARY_HEADERS) #include +#endif #if defined(MBEDTLS_USE_PSA_CRYPTO) #include "mbedtls/psa_util.h"