[Crypto] Delete mbedtls ctx in deconstructor.

Would cause memory leak when the context was `start`ed but not
`finish`ed.

(cherry picked from commit a28d25c441)
This commit is contained in:
Fabio Alessandrelli 2021-07-03 16:12:55 +02:00 committed by Rémi Verschelde
parent 245b9400ea
commit 32e91b232c
No known key found for this signature in database
GPG key ID: C3336907360768E1
3 changed files with 9 additions and 0 deletions

View file

@ -83,6 +83,7 @@ public:
virtual PoolByteArray finish() = 0;
HMACContext() {}
virtual ~HMACContext() {}
};
class Crypto : public Reference {

View file

@ -255,6 +255,13 @@ PoolByteArray 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);
}

View file

@ -119,6 +119,7 @@ public:
virtual PoolByteArray finish();
HMACContextMbedTLS() {}
~HMACContextMbedTLS();
};
class CryptoMbedTLS : public Crypto {