From 42e111f26b96bd3703b44653fe9871f2e6b7e915 Mon Sep 17 00:00:00 2001 From: He Yang <1160386205@qq.com> Date: Fri, 25 Jun 2021 03:20:01 +0530 Subject: [PATCH] [ATL] Close m_hKey in CRegKey destructor and when attaching to a new key (#3764) --- sdk/lib/atl/atlbase.h | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/sdk/lib/atl/atlbase.h b/sdk/lib/atl/atlbase.h index fa3cf72cd8a..502d7b1ad44 100644 --- a/sdk/lib/atl/atlbase.h +++ b/sdk/lib/atl/atlbase.h @@ -1043,6 +1043,7 @@ public: ~CRegKey() throw() { + Close(); } void Attach(HKEY hKey) throw() @@ -1359,7 +1360,11 @@ public: CRegKey& operator=(CRegKey& key) throw() { - Attach(key.Detach()); + if (m_hKey != key.m_hKey) + { + Close(); + Attach(key.Detach()); + } return *this; }