@KindDragon You're completely correct! Thanks a lot for having pointed at this.

 I fixed as well the definition of the `NullRepositorySafeHandle` type. My proposal was indeed a bit hasty. :blush:

Applying the following patch should now make the code behave as expected

```diff
diff --git a/LibGit2Sharp/Core/Handles/NullRepositorySafeHandle.cs b/LibGit2Sharp/Core/Handles/NullRepositorySafeHandle.cs
index fa00b0b..cf57b96 100644
--- a/LibGit2Sharp/Core/Handles/NullRepositorySafeHandle.cs
+++ b/LibGit2Sharp/Core/Handles/NullRepositorySafeHandle.cs
@@ -2,7 +2,7 @@
 
 namespace LibGit2Sharp.Core.Handles
 {
-    internal class NullRepositorySafeHandle : GitObjectSafeHandle
+    internal class NullRepositorySafeHandle : SafeHandleBase
     {
         public NullRepositorySafeHandle()
         {
diff --git a/LibGit2Sharp/Core/NativeMethods.cs b/LibGit2Sharp/Core/NativeMethods.cs
index 10b9332..022f824 100644
--- a/LibGit2Sharp/Core/NativeMethods.cs
+++ b/LibGit2Sharp/Core/NativeMethods.cs
@@ -907,7 +907,7 @@ private static bool IsRunningOnLinux()
 
         [DllImport(libgit2)]
         internal static extern int git_repository_open_ext(
-            out NullRepositorySafeHandle repository,
+            NullRepositorySafeHandle repository,
             [MarshalAs(UnmanagedType.CustomMarshaler, MarshalTypeRef = typeof(FilePathMarshaler))] FilePath path,
             RepositoryOpenFlags flags,
             [MarshalAs(UnmanagedType.CustomMarshaler, MarshalTypeRef = typeof(FilePathMarshaler))] FilePath ceilingDirs);
diff --git a/LibGit2Sharp/Core/Proxy.cs b/LibGit2Sharp/Core/Proxy.cs
index 5df546c..b6529b4 100644
--- a/LibGit2Sharp/Core/Proxy.cs
+++ b/LibGit2Sharp/Core/Proxy.cs
@@ -1658,10 +1658,15 @@ public static void git_repository_open_ext(string path, RepositoryOpenFlags flag
         {
             using (ThreadAffinity())
             {
-                NullRepositorySafeHandle repo;
+                int res;
+
+                using (var repo = new NullRepositorySafeHandle())
+                {
+                    res = NativeMethods.git_repository_open_ext(repo, path, flags, ceilingDirs);
 
-                int res = NativeMethods.git_repository_open_ext(out repo, path, flags, ceilingDirs);
-                repo.Dispose();
+                    // To be removed before final merge
+                    System.Diagnostics.Debug.Assert(repo.DangerousGetHandle() == IntPtr.Zero);
+                }
 
                 if (res == (int)GitErrorCode.NotFound)
                 {
```