From 1aa1cf155ec13bd7e8a40b2f831cfce035b4391d Mon Sep 17 00:00:00 2001 From: "Liening.Liu" Date: Thu, 18 Aug 2022 09:40:00 +0800 Subject: [PATCH] Release the memory allocated in the algorithm to prevent memory leaks In the reference implementation of the identity function, there are two places where the memory requested in the openssl algorithm is not released. This memory should be freed. Test: Vts/Cts Bug: 242927524 Change-Id: I88ffba39cb6ec887f395122e4670bf9f1a2d8e12 --- identity/aidl/default/EicOpsImpl.cc | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/identity/aidl/default/EicOpsImpl.cc b/identity/aidl/default/EicOpsImpl.cc index 3fd9f1dcee..b6d324f1cc 100644 --- a/identity/aidl/default/EicOpsImpl.cc +++ b/identity/aidl/default/EicOpsImpl.cc @@ -100,6 +100,7 @@ void eicOpsHmacSha256Final(EicHmacSha256Ctx* ctx, uint8_t digest[EIC_SHA256_DIGE if (size != EIC_SHA256_DIGEST_SIZE) { LOG(ERROR) << "Expected 32 bytes from HMAC_Final, got " << size; } + HMAC_CTX_cleanup(realCtx); } void eicOpsSha256Init(EicSha256Ctx* ctx) { @@ -394,14 +395,17 @@ bool eicOpsEcDsa(const uint8_t privateKey[EIC_P256_PRIV_KEY_SIZE], } if (BN_bn2binpad(sig->r, signature, 32) != 32) { + ECDSA_SIG_free(sig); eicDebug("Error encoding r"); return false; } if (BN_bn2binpad(sig->s, signature + 32, 32) != 32) { + ECDSA_SIG_free(sig); eicDebug("Error encoding s"); return false; } + ECDSA_SIG_free(sig); return true; }