瀏覽代碼

[Crypto] Delete mbedtls ctx in deconstructor.

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

(cherry picked from commit a28d25c44181ded80c80f7ae18ea75ce28e00eec)
Fabio Alessandrelli 4 年之前
父節點
當前提交
32e91b232c
共有 3 個文件被更改,包括 9 次插入0 次删除
  1. 1 0
      core/crypto/crypto.h
  2. 7 0
      modules/mbedtls/crypto_mbedtls.cpp
  3. 1 0
      modules/mbedtls/crypto_mbedtls.h

+ 1 - 0
core/crypto/crypto.h

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

+ 7 - 0
modules/mbedtls/crypto_mbedtls.cpp

@@ -255,6 +255,13 @@ PoolByteArray HMACContextMbedTLS::finish() {
 	return out;
 	return out;
 }
 }
 
 
+HMACContextMbedTLS::~HMACContextMbedTLS() {
+	if (ctx != nullptr) {
+		mbedtls_md_free((mbedtls_md_context_t *)ctx);
+		memfree((mbedtls_md_context_t *)ctx);
+	}
+}
+
 Crypto *CryptoMbedTLS::create() {
 Crypto *CryptoMbedTLS::create() {
 	return memnew(CryptoMbedTLS);
 	return memnew(CryptoMbedTLS);
 }
 }

+ 1 - 0
modules/mbedtls/crypto_mbedtls.h

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