[ATL] Close m_hKey in CRegKey destructor and when attaching to a new key (#3764)
authorHe Yang <1160386205@qq.com>
Thu, 24 Jun 2021 21:50:01 +0000 (03:20 +0530)
committerGitHub <noreply@github.com>
Thu, 24 Jun 2021 21:50:01 +0000 (23:50 +0200)
sdk/lib/atl/atlbase.h

index fa3cf72..502d7b1 100644 (file)
@@ -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;
     }