Skip to content

Commit

Permalink
Introduce EncodingMarshaler.Cleanup()
Browse files Browse the repository at this point in the history
  • Loading branch information
nulltoken committed Oct 15, 2013
1 parent 11f4cb8 commit 75eaceb
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 15 deletions.
17 changes: 11 additions & 6 deletions LibGit2Sharp/Core/EncodingMarshaler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,7 @@ public void CleanUpManagedData(object managedObj)

public virtual void CleanUpNativeData(IntPtr pNativeData)
{
if (pNativeData == IntPtr.Zero)
{
return;
}

Marshal.FreeHGlobal(pNativeData);
Cleanup(pNativeData);
}

public int GetNativeDataSize()
Expand Down Expand Up @@ -83,6 +78,16 @@ public static unsafe IntPtr FromManaged(Encoding encoding, String value)
return new IntPtr(buffer);
}

public static void Cleanup(IntPtr pNativeData)
{
if (pNativeData == IntPtr.Zero)
{
return;
}

Marshal.FreeHGlobal(pNativeData);
}

public static unsafe String FromNative(Encoding encoding, IntPtr pNativeData)
{
if (pNativeData == IntPtr.Zero)
Expand Down
7 changes: 1 addition & 6 deletions LibGit2Sharp/Core/GitRepositoryInitOptions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -41,12 +41,7 @@ public static GitRepositoryInitOptions BuildFrom(FilePath workdirPath, bool isBa

public void Dispose()
{
if (WorkDirPath == IntPtr.Zero)
{
return;
}

Marshal.FreeHGlobal(WorkDirPath);
EncodingMarshaler.Cleanup(WorkDirPath);
WorkDirPath = IntPtr.Zero;
}
}
Expand Down
2 changes: 1 addition & 1 deletion LibGit2Sharp/Core/GitStrArrayIn.cs
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ public void Dispose()

for (int i = 0; i < nbOfPaths; i++)
{
Marshal.FreeHGlobal(pathPtrs[i]);
EncodingMarshaler.Cleanup(pathPtrs[i]);
}

Marshal.FreeHGlobal(strings);
Expand Down
3 changes: 1 addition & 2 deletions LibGit2Sharp/Index.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
using System.Globalization;
using System.IO;
using System.Linq;
using System.Runtime.InteropServices;
using LibGit2Sharp.Core;
using LibGit2Sharp.Core.Compat;
using LibGit2Sharp.Core.Handles;
Expand Down Expand Up @@ -554,7 +553,7 @@ private void ReplaceIndexEntryWith(TreeEntryChanges treeEntryChanges)
};

Proxy.git_index_add(handle, indexEntry);
Marshal.FreeHGlobal(indexEntry.Path);
EncodingMarshaler.Cleanup(indexEntry.Path);
}

internal void ReloadFromDisk()
Expand Down

0 comments on commit 75eaceb

Please sign in to comment.