Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Better safehandles #2130

Draft
wants to merge 3 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions LibGit2Sharp/Core/Handles/Libgit2Object.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
//#define LEAKS_TRACKING

using System;
using Microsoft.Win32.SafeHandles;
using System.Runtime.InteropServices;

#if LEAKS_IDENTIFYING
namespace LibGit2Sharp.Core
Expand Down Expand Up @@ -83,7 +83,7 @@ namespace LibGit2Sharp.Core.Handles
using System.Globalization;
#endif

internal unsafe abstract class Libgit2Object : SafeHandleZeroOrMinusOneIsInvalid
internal unsafe abstract class Libgit2Object : SafeHandle
{
#if LEAKS_TRACKING
private readonly string trace;
Expand All @@ -96,7 +96,7 @@ internal unsafe Libgit2Object(void* ptr, bool owned)
}

internal unsafe Libgit2Object(IntPtr ptr, bool owned)
: base(owned)
: base(IntPtr.Zero, owned)
{
SetHandle(ptr);

Expand All @@ -108,12 +108,12 @@ internal unsafe Libgit2Object(IntPtr ptr, bool owned)
#endif
}

internal IntPtr AsIntPtr() => DangerousGetHandle();
public override bool IsInvalid => handle == IntPtr.Zero;

protected override void Dispose(bool disposing)
{
#if LEAKS_IDENTIFYING
bool leaked = !disposing && DangerousGetHandle() != IntPtr.Zero;
bool leaked = !disposing && !IsInvalid;

if (leaked)
{
Expand Down
Loading