diff --git a/matter/mbedtls/tinycrypt/src/pk.c b/matter/mbedtls/tinycrypt/src/pk.c index f498935ee8..6bfc165a65 100644 --- a/matter/mbedtls/tinycrypt/src/pk.c +++ b/matter/mbedtls/tinycrypt/src/pk.c @@ -95,8 +95,9 @@ void mbedtls_pk_free(mbedtls_pk_context *ctx) { if (ctx == NULL) return; - if (ctx->pk_info != NULL) + if ((ctx->pk_info != NULL) && (ctx->pk_info->ctx_free_func != NULL)) { ctx->pk_info->ctx_free_func(ctx->pk_ctx); + } mbedtls_platform_zeroize(ctx, sizeof(mbedtls_pk_context)); }