From f06897e0c18dea7d0b50b2f4b1dd613c2f164614 Mon Sep 17 00:00:00 2001 From: Steven Cooreman Date: Thu, 18 Aug 2022 19:54:43 +0200 Subject: [PATCH] [EFR32] Fix resource leak on volatile keys (#22006) * [EFR32] Fix a resource leak on volatile key destruction * [EFR32] Fix key lifetime not always being attributed correctly --- 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);