From a28d25c44181ded80c80f7ae18ea75ce28e00eec Mon Sep 17 00:00:00 2001 From: Fabio Alessandrelli Date: Sat, 3 Jul 2021 16:12:55 +0200 Subject: [Crypto] Delete mbedtls ctx in deconstructor. Would cause memory leak when the context was `start`ed but not `finish`ed. --- modules/mbedtls/crypto_mbedtls.cpp | 7 +++++++ modules/mbedtls/crypto_mbedtls.h | 1 + 2 files changed, 8 insertions(+) (limited to 'modules/mbedtls') diff --git a/modules/mbedtls/crypto_mbedtls.cpp b/modules/mbedtls/crypto_mbedtls.cpp index 774da5a324..2522f1bb11 100644 --- a/modules/mbedtls/crypto_mbedtls.cpp +++ b/modules/mbedtls/crypto_mbedtls.cpp @@ -249,6 +249,13 @@ PackedByteArray HMACContextMbedTLS::finish() { return out; } +HMACContextMbedTLS::~HMACContextMbedTLS() { + if (ctx != nullptr) { + mbedtls_md_free((mbedtls_md_context_t *)ctx); + memfree((mbedtls_md_context_t *)ctx); + } +} + Crypto *CryptoMbedTLS::create() { return memnew(CryptoMbedTLS); } diff --git a/modules/mbedtls/crypto_mbedtls.h b/modules/mbedtls/crypto_mbedtls.h index 5ced4d136c..afa1ea7a64 100644 --- a/modules/mbedtls/crypto_mbedtls.h +++ b/modules/mbedtls/crypto_mbedtls.h @@ -119,6 +119,7 @@ public: virtual PackedByteArray finish(); HMACContextMbedTLS() {} + ~HMACContextMbedTLS(); }; class CryptoMbedTLS : public Crypto { -- cgit v1.2.3