From 763ee3c6b46d591135e3576c41f944c92568f104 Mon Sep 17 00:00:00 2001 From: Leonid Rozenboim Date: Thu, 21 Apr 2022 13:05:10 -0700 Subject: [PATCH] Fix resource leaks These potential leaks were flagged by the Coverity static analyzer. Signed-off-by: Leonid Rozenboim --- library/pkparse.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/library/pkparse.c b/library/pkparse.c index 535ed70eb..8dc2f93f6 100644 --- a/library/pkparse.c +++ b/library/pkparse.c @@ -1465,8 +1465,10 @@ int mbedtls_pk_parse_public_key( mbedtls_pk_context *ctx, if( ( pk_info = mbedtls_pk_info_from_type( MBEDTLS_PK_RSA ) ) == NULL ) return( MBEDTLS_ERR_PK_UNKNOWN_PK_ALG ); - if( ( ret = mbedtls_pk_setup( ctx, pk_info ) ) != 0 ) + if( ( ret = mbedtls_pk_setup( ctx, pk_info ) ) != 0 ) { + mbedtls_pem_free( &pem ); return( ret ); + } if ( ( ret = pk_get_rsapubkey( &p, p + pem.buflen, mbedtls_pk_rsa( *ctx ) ) ) != 0 ) mbedtls_pk_free( ctx );