Destroy handle on UMEntryThunk::Terminate
authormateoatr <matorre@microsoft.com>
Mon, 9 Dec 2019 17:11:22 +0000 (17:11 +0000)
committermateoatr <matorre@microsoft.com>
Mon, 9 Dec 2019 17:11:22 +0000 (17:11 +0000)
src/coreclr/src/vm/comdelegate.cpp
src/coreclr/src/vm/dllimportcallback.cpp
src/coreclr/src/vm/dllimportcallback.h

index a1e403b..c703333 100644 (file)
@@ -1307,9 +1307,7 @@ LPVOID COMDelegate::ConvertToCallback(OBJECTREF pDelegateObj)
             umHolder.Assign(pUMEntryThunk);
 
             // multicast. go thru Invoke
-            OBJECTHANDLE objhnd = pUMEntryThunk->GetObjectHandle();
-            if (objhnd == NULL)
-                objhnd = GetAppDomain()->CreateLongWeakHandle(pDelegate);
+            OBJECTHANDLE objhnd = GetAppDomain()->CreateLongWeakHandle(pDelegate);
             _ASSERTE(objhnd != NULL);
 
             // This target should not ever be used. We are storing it in the thunk for better diagnostics of "call on collected delegate" crashes.
index 3960ba8..3c8b501 100644 (file)
@@ -961,12 +961,18 @@ void UMEntryThunk::Terminate()
     CONTRACTL
     {
         NOTHROW;
+        MODE_ANY;
     }
     CONTRACTL_END;
 
     m_code.Poison();
 
     s_thunkFreeList.AddToList(this);
+
+    if (GetObjectHandle())
+    {
+        DestroyLongWeakHandle(GetObjectHandle());
+    }
 }
 
 VOID UMEntryThunk::FreeUMEntryThunk(UMEntryThunk* p)
index 6c909cb..6fe9e64 100644 (file)
@@ -310,22 +310,6 @@ public:
 #endif
     }
 
-    ~UMEntryThunk()
-    {
-        CONTRACTL
-        {
-            NOTHROW;
-            GC_NOTRIGGER;
-            MODE_ANY;
-        }
-        CONTRACTL_END;
-
-        if (GetObjectHandle())
-        {
-            DestroyLongWeakHandle(GetObjectHandle());
-        }
-    }
-
     void Terminate();
 
     VOID RunTimeInit()