Fetch secondary handle only if primary is non-null
authorJan Kotas <jkotas@microsoft.com>
Sat, 29 Apr 2017 14:43:23 +0000 (07:43 -0700)
committerJan Kotas <jkotas@microsoft.com>
Mon, 1 May 2017 17:29:50 +0000 (10:29 -0700)
The GC is not tracking the secondary handle once primary gets cleared.

Fixes dotnet/coreclr#11270

Commit migrated from https://github.com/dotnet/coreclr/commit/d9b076c50a6781418a01c1baa166cba0ab15e229

src/coreclr/src/vm/comdependenthandle.cpp

index 0f33821..4763e48 100644 (file)
@@ -69,8 +69,14 @@ FCIMPLEND
 FCIMPL2(Object*, DependentHandle::nGetPrimaryAndSecondary, OBJECTHANDLE handle, Object **outSecondary)
 {
     FCALL_CONTRACT;
-    *outSecondary = OBJECTREFToObject(GetDependentHandleSecondary(handle));
-    return OBJECTREFToObject(ObjectFromHandle(handle));
+    _ASSERTE(handle != NULL && outSecondary != NULL);
+
+    OBJECTREF primary = ObjectFromHandle(handle);
+
+    // Secondary is tracked only if primary is non-null
+    *outSecondary = (primary != NULL) ? OBJECTREFToObject(GetDependentHandleSecondary(handle)) : NULL;
+
+    return OBJECTREFToObject(primary);
 }
 FCIMPLEND