From 072d2b094d32e74cfb5150b8d9e95bc6fc2e8986 Mon Sep 17 00:00:00 2001 From: Paul Elliott Date: Fri, 13 May 2022 17:08:36 +0100 Subject: [PATCH] Add pem_free() to other error paths in pk_parse_public_key() Signed-off-by: Paul Elliott --- library/pkparse.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/library/pkparse.c b/library/pkparse.c index bb5824fc3e..11afd0bdf7 100644 --- a/library/pkparse.c +++ b/library/pkparse.c @@ -1453,10 +1453,14 @@ int mbedtls_pk_parse_public_key( mbedtls_pk_context *ctx, if( ret == 0 ) { p = pem.buf; - if( ( pk_info = mbedtls_pk_info_from_type( MBEDTLS_PK_RSA ) ) == NULL ) + if( ( pk_info = mbedtls_pk_info_from_type( MBEDTLS_PK_RSA )) == NULL ) + { + mbedtls_pem_free( &pem ); 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 ); }