Fix race condition (dotnet/coreclr#7928)
authorDmitry-Me <Dmitry-Me@users.noreply.github.com>
Thu, 3 Nov 2016 01:38:49 +0000 (04:38 +0300)
committerJan Vorlicek <janvorli@microsoft.com>
Thu, 3 Nov 2016 01:38:49 +0000 (18:38 -0700)
Commit migrated from https://github.com/dotnet/coreclr/commit/578ea10d73f82f156f9fea76ddf915b7943d7bd8

src/coreclr/src/debug/ee/controller.h

index 6611e04..a314874 100644 (file)
@@ -227,23 +227,23 @@ public:
 
     LONG AddRef()
     {
-        InterlockedIncrement(&m_refCount);
-        _ASSERTE(m_refCount > 0);
-        return m_refCount;
+        LONG newRefCount = InterlockedIncrement(&m_refCount);
+        _ASSERTE(newRefCount > 0);
+        return newRefCount;
     }
 
     LONG Release()
     {
-        LONG result = InterlockedDecrement(&m_refCount);
-        _ASSERTE(m_refCount >= 0);
+        LONG newRefCount = InterlockedDecrement(&m_refCount);
+        _ASSERTE(newRefCount >= 0);
 
-        if (m_refCount == 0)
+        if (newRefCount == 0)
         {
             TRACE_FREE(this);
             DeleteInteropSafeExecutable(this);
         }
 
-        return result;
+        return newRefCount;
     }
 
     // "PatchBypass" must be the first field of this class for alignment to be correct.