Skip to content

Commit

Permalink
[EFR32] Fix resource leak on volatile keys (#22006)
Browse files Browse the repository at this point in the history
* [EFR32] Fix a resource leak on volatile key destruction

* [EFR32] Fix key lifetime not always being attributed correctly
  • Loading branch information
stevew817 authored Aug 18, 2022
1 parent 507bb70 commit 3acafb1
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions src/platform/EFR32/Efr32PsaOpaqueKeypair.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down Expand Up @@ -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);
Expand Down

0 comments on commit 3acafb1

Please sign in to comment.