From d9501d7cbab1ea4b1bf6b51f8eda178f6dad6ddb Mon Sep 17 00:00:00 2001 From: Jan Kotas Date: Sat, 29 Apr 2017 07:43:23 -0700 Subject: [PATCH] Fetch secondary handle only if primary is non-null 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 | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/src/coreclr/src/vm/comdependenthandle.cpp b/src/coreclr/src/vm/comdependenthandle.cpp index 0f33821..4763e48 100644 --- a/src/coreclr/src/vm/comdependenthandle.cpp +++ b/src/coreclr/src/vm/comdependenthandle.cpp @@ -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 -- 2.7.4