Address reliability issue with setting ITypeInfo (#42560)
authorAaron Robinson <arobins@microsoft.com>
Tue, 22 Sep 2020 21:27:00 +0000 (14:27 -0700)
committerGitHub <noreply@github.com>
Tue, 22 Sep 2020 21:27:00 +0000 (14:27 -0700)
src/coreclr/src/vm/assembly.cpp
src/coreclr/src/vm/comcallablewrapper.cpp
src/coreclr/src/vm/stdinterfaces.cpp

index 4934ae6..0e61a2e 100644 (file)
@@ -1965,7 +1965,7 @@ bool Assembly::TrySetTypeLib(_In_ ITypeLib *pNew)
         pNew->AddRef();
 
     return true;
-} // void Assembly::SetTypeLib()
+} // void Assembly::TrySetTypeLib()
 
 #endif // FEATURE_COMINTEROP
 
index aa3068a..8ca74e4 100644 (file)
@@ -4089,14 +4089,10 @@ void ComMethodTable::SetITypeInfo(ITypeInfo *pNew)
     }
     CONTRACTL_END;
 
-    SafeComHolder<ITypeInfo> pOld;
-    pOld = InterlockedExchangeT(&m_pITypeInfo, pNew);
-
-    // TypeLibs are refcounted pointers.
-    if (pNew == pOld)
-        pOld.SuppressRelease();
-    else
+    if (InterlockedCompareExchangeT(&m_pITypeInfo, pNew, NULL) == NULL)
+    {
         SafeAddRef(pNew);
+    }
 }
 
 //--------------------------------------------------------------------------
index 1913546..ab964e4 100644 (file)
@@ -799,7 +799,7 @@ HRESULT GetITypeInfoForMT(ComMethodTable *pMT, ITypeInfo **ppTI)
 
     pTI = pMT->GetITypeInfo();
 
-    if (pTI == 0)
+    if (pTI == NULL)
     {
         MethodTable *pClass = pMT->GetMethodTable();
 
@@ -809,6 +809,7 @@ HRESULT GetITypeInfoForMT(ComMethodTable *pMT, ITypeInfo **ppTI)
         {
             pMT->SetITypeInfo(pTI);
             SafeReleasePreemp(pTI);
+            pTI = pMT->GetITypeInfo();
         }
     }