Skip to content

Commit

Permalink
Make debug-only SafeHandle _ctorStackTrace coreclr-only
Browse files Browse the repository at this point in the history
  • Loading branch information
stephentoub committed Feb 21, 2023
1 parent a4c9243 commit 2497e7d
Showing 1 changed file with 4 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ namespace System.Runtime.InteropServices
/// <summary>Represents a wrapper class for operating system handles.</summary>
public abstract partial class SafeHandle : CriticalFinalizerObject, IDisposable
{
#if DEBUG
#if DEBUG && CORECLR
/// <summary>Indicates whether debug tracking and logging of SafeHandle finalization is enabled.</summary>
private static readonly bool s_logFinalization = Environment.GetEnvironmentVariable("DEBUG_SAFEHANDLE_FINALIZATION") == "1";
/// <summary>Debug counter for the number of SafeHandles that have been finalized.</summary>
Expand All @@ -28,7 +28,7 @@ public abstract partial class SafeHandle : CriticalFinalizerObject, IDisposable
// code, so this managed code must not assume it is the only code
// manipulating _state.

#if DEBUG
#if DEBUG && CORECLR
private readonly string? _ctorStackTrace;
#endif
/// <summary>Specifies the handle to be wrapped.</summary>
Expand Down Expand Up @@ -71,7 +71,7 @@ protected SafeHandle(IntPtr invalidHandleValue, bool ownsHandle)
{
GC.SuppressFinalize(this);
}
#if DEBUG
#if DEBUG && CORECLR
else if (s_logFinalization)
{
int lastError = Marshal.GetLastPInvokeError();
Expand Down Expand Up @@ -111,7 +111,7 @@ public void Dispose()

protected virtual void Dispose(bool disposing)
{
#if DEBUG
#if DEBUG && CORECLR
if (!disposing && _ctorStackTrace is not null)
{
long count = Interlocked.Increment(ref s_safeHandlesFinalized);
Expand Down

0 comments on commit 2497e7d

Please sign in to comment.