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 #11270

src/vm/comdependenthandle.cpp

index 0f338217c9bf4256d88f43d7930c15d28f52083a..4763e4833a821b98e0e899e8d3d8320e5750a322 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