diff --git a/library/pkparse.c b/library/pkparse.c index 8dc2f93f693f..36ddbeec4def 100644 --- a/library/pkparse.c +++ b/library/pkparse.c @@ -1462,10 +1462,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 ); }