From 7f02facf8985069cb503508250e96bb41db06a80 Mon Sep 17 00:00:00 2001 From: Aidan Garske Date: Thu, 10 Sep 2026 11:29:28 -0700 Subject: [PATCH] F-12707 - Clean up wolfCrypt only when its init succeeded --- src/fwtpm/fwtpm.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/fwtpm/fwtpm.c b/src/fwtpm/fwtpm.c index 1d6c2b0b..12d65372 100644 --- a/src/fwtpm/fwtpm.c +++ b/src/fwtpm/fwtpm.c @@ -40,6 +40,7 @@ int FWTPM_Init(FWTPM_CTX* ctx) { int rc; int rngInit = 0; + int wcInit = 0; FWTPM_NV_HAL savedNvHal; struct FWTPM_CLOCK_HAL_S savedClockHal; #ifndef FWTPM_NO_PP @@ -96,6 +97,7 @@ int FWTPM_Init(FWTPM_CTX* ctx) /* Initialize wolfCrypt RNG */ rc = wolfCrypt_Init(); if (rc == 0) { + wcInit = 1; rc = wc_InitRng(&ctx->rng); if (rc == 0) { rngInit = 1; @@ -141,7 +143,9 @@ int FWTPM_Init(FWTPM_CTX* ctx) if (rngInit) { wc_FreeRng(&ctx->rng); } - wolfCrypt_Cleanup(); + if (wcInit) { + wolfCrypt_Cleanup(); + } } return rc;