Fix memory leak on failure path in test code

Signed-off-by: Manuel Pégourié-Gonnard <manuel.pegourie-gonnard@arm.com>
This commit is contained in:
Manuel Pégourié-Gonnard 2021-07-06 12:05:23 +02:00
parent bd3bfbf5c2
commit 69c10a41c7

View file

@ -167,7 +167,8 @@ int ssl_check_record( mbedtls_ssl_context const *ssl,
if( ret != ret_repeated ) if( ret != ret_repeated )
{ {
mbedtls_printf( "mbedtls_ssl_check_record() returned inconsistent results.\n" ); mbedtls_printf( "mbedtls_ssl_check_record() returned inconsistent results.\n" );
return( -1 ); ret = -1;
goto cleanup;
} }
switch( ret ) switch( ret )
@ -178,29 +179,34 @@ int ssl_check_record( mbedtls_ssl_context const *ssl,
case MBEDTLS_ERR_SSL_INVALID_RECORD: case MBEDTLS_ERR_SSL_INVALID_RECORD:
if( opt.debug_level > 1 ) if( opt.debug_level > 1 )
mbedtls_printf( "mbedtls_ssl_check_record() detected invalid record.\n" ); mbedtls_printf( "mbedtls_ssl_check_record() detected invalid record.\n" );
ret = 0;
break; break;
case MBEDTLS_ERR_SSL_INVALID_MAC: case MBEDTLS_ERR_SSL_INVALID_MAC:
if( opt.debug_level > 1 ) if( opt.debug_level > 1 )
mbedtls_printf( "mbedtls_ssl_check_record() detected unauthentic record.\n" ); mbedtls_printf( "mbedtls_ssl_check_record() detected unauthentic record.\n" );
ret = 0;
break; break;
case MBEDTLS_ERR_SSL_UNEXPECTED_RECORD: case MBEDTLS_ERR_SSL_UNEXPECTED_RECORD:
if( opt.debug_level > 1 ) if( opt.debug_level > 1 )
mbedtls_printf( "mbedtls_ssl_check_record() detected unexpected record.\n" ); mbedtls_printf( "mbedtls_ssl_check_record() detected unexpected record.\n" );
ret = 0;
break; break;
default: default:
mbedtls_printf( "mbedtls_ssl_check_record() failed fatally with -%#04x.\n", (unsigned int) -ret ); mbedtls_printf( "mbedtls_ssl_check_record() failed fatally with -%#04x.\n", (unsigned int) -ret );
return( -1 ); ret = -1;
goto cleanup;
} }
/* Regardless of the outcome, forward the record to the stack. */ /* Regardless of the outcome, forward the record to the stack. */
} }
cleanup:
mbedtls_free( tmp_buf ); mbedtls_free( tmp_buf );
return( 0 ); return( ret );
} }
int recv_cb( void *ctx, unsigned char *buf, size_t len ) int recv_cb( void *ctx, unsigned char *buf, size_t len )