From d7b7464c3bd141d26afc8799e4c0e1642f425209 Mon Sep 17 00:00:00 2001 From: Justin Wood Date: Thu, 18 Aug 2022 14:10:12 -0700 Subject: [PATCH] [EFR32] Fix resource leak on volatile keys (#22006) (#22013) * [EFR32] Fix a resource leak on volatile key destruction * [EFR32] Fix key lifetime not always being attributed correctly Co-authored-by: Steven Cooreman --- src/platform/EFR32/Efr32PsaOpaqueKeypair.cpp | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/src/platform/EFR32/Efr32PsaOpaqueKeypair.cpp b/src/platform/EFR32/Efr32PsaOpaqueKeypair.cpp index add77c1be63e51..b1c32dc028471d 100644 --- a/src/platform/EFR32/Efr32PsaOpaqueKeypair.cpp +++ b/src/platform/EFR32/Efr32PsaOpaqueKeypair.cpp @@ -118,9 +118,15 @@ EFR32OpaqueKeypair::EFR32OpaqueKeypair() EFR32OpaqueKeypair::~EFR32OpaqueKeypair() { - // Free dynamic resource + // Free key resources if (mContext != nullptr) { + // Delete volatile keys, since nobody else can after we drop the key ID. + if (!mIsPersistent) + { + Delete(); + } + MemoryFree(mContext); mContext = nullptr; } @@ -244,7 +250,7 @@ CHIP_ERROR EFR32OpaqueKeypair::Create(EFR32OpaqueKeyId opaque_id, EFR32OpaqueKey // Store the key ID and mark the key as valid mHasKey = true; - mIsPersistent = key_id != kEFR32OpaqueKeyIdVolatile; + mIsPersistent = opaque_id != kEFR32OpaqueKeyIdVolatile; exit: psa_reset_key_attributes(&attr);