Skip to content

Commit 52acd01

Browse files
committed
Use SafeHandle as base class
1 parent 0eed453 commit 52acd01

File tree

1 file changed

+6
-4
lines changed

1 file changed

+6
-4
lines changed

LibGit2Sharp/Core/Handles/Libgit2Object.cs

+6-4
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
//#define LEAKS_TRACKING
1919

2020
using System;
21-
using Microsoft.Win32.SafeHandles;
21+
using System.Runtime.InteropServices;
2222

2323
#if LEAKS_IDENTIFYING
2424
namespace LibGit2Sharp.Core
@@ -83,7 +83,7 @@ namespace LibGit2Sharp.Core.Handles
8383
using System.Globalization;
8484
#endif
8585

86-
internal unsafe abstract class Libgit2Object : SafeHandleZeroOrMinusOneIsInvalid
86+
internal unsafe abstract class Libgit2Object : SafeHandle
8787
{
8888
#if LEAKS_TRACKING
8989
private readonly string trace;
@@ -96,7 +96,7 @@ internal unsafe Libgit2Object(void* ptr, bool owned)
9696
}
9797

9898
internal unsafe Libgit2Object(IntPtr ptr, bool owned)
99-
: base(owned)
99+
: base(IntPtr.Zero, owned)
100100
{
101101
SetHandle(ptr);
102102

@@ -108,12 +108,14 @@ internal unsafe Libgit2Object(IntPtr ptr, bool owned)
108108
#endif
109109
}
110110

111+
public override bool IsInvalid => handle == IntPtr.Zero;
112+
111113
internal IntPtr AsIntPtr() => DangerousGetHandle();
112114

113115
protected override void Dispose(bool disposing)
114116
{
115117
#if LEAKS_IDENTIFYING
116-
bool leaked = !disposing && DangerousGetHandle() != IntPtr.Zero;
118+
bool leaked = !disposing && !IsInvalid;
117119

118120
if (leaked)
119121
{

0 commit comments

Comments
 (0)