Skip to content

Commit 75eaceb

Browse files
committed
Introduce EncodingMarshaler.Cleanup()
1 parent 11f4cb8 commit 75eaceb

File tree

4 files changed

+14
-15
lines changed

4 files changed

+14
-15
lines changed

LibGit2Sharp/Core/EncodingMarshaler.cs

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -21,12 +21,7 @@ public void CleanUpManagedData(object managedObj)
2121

2222
public virtual void CleanUpNativeData(IntPtr pNativeData)
2323
{
24-
if (pNativeData == IntPtr.Zero)
25-
{
26-
return;
27-
}
28-
29-
Marshal.FreeHGlobal(pNativeData);
24+
Cleanup(pNativeData);
3025
}
3126

3227
public int GetNativeDataSize()
@@ -83,6 +78,16 @@ public static unsafe IntPtr FromManaged(Encoding encoding, String value)
8378
return new IntPtr(buffer);
8479
}
8580

81+
public static void Cleanup(IntPtr pNativeData)
82+
{
83+
if (pNativeData == IntPtr.Zero)
84+
{
85+
return;
86+
}
87+
88+
Marshal.FreeHGlobal(pNativeData);
89+
}
90+
8691
public static unsafe String FromNative(Encoding encoding, IntPtr pNativeData)
8792
{
8893
if (pNativeData == IntPtr.Zero)

LibGit2Sharp/Core/GitRepositoryInitOptions.cs

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -41,12 +41,7 @@ public static GitRepositoryInitOptions BuildFrom(FilePath workdirPath, bool isBa
4141

4242
public void Dispose()
4343
{
44-
if (WorkDirPath == IntPtr.Zero)
45-
{
46-
return;
47-
}
48-
49-
Marshal.FreeHGlobal(WorkDirPath);
44+
EncodingMarshaler.Cleanup(WorkDirPath);
5045
WorkDirPath = IntPtr.Zero;
5146
}
5247
}

LibGit2Sharp/Core/GitStrArrayIn.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ public void Dispose()
4545

4646
for (int i = 0; i < nbOfPaths; i++)
4747
{
48-
Marshal.FreeHGlobal(pathPtrs[i]);
48+
EncodingMarshaler.Cleanup(pathPtrs[i]);
4949
}
5050

5151
Marshal.FreeHGlobal(strings);

LibGit2Sharp/Index.cs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
using System.Globalization;
66
using System.IO;
77
using System.Linq;
8-
using System.Runtime.InteropServices;
98
using LibGit2Sharp.Core;
109
using LibGit2Sharp.Core.Compat;
1110
using LibGit2Sharp.Core.Handles;
@@ -554,7 +553,7 @@ private void ReplaceIndexEntryWith(TreeEntryChanges treeEntryChanges)
554553
};
555554

556555
Proxy.git_index_add(handle, indexEntry);
557-
Marshal.FreeHGlobal(indexEntry.Path);
556+
EncodingMarshaler.Cleanup(indexEntry.Path);
558557
}
559558

560559
internal void ReloadFromDisk()

0 commit comments

Comments
 (0)