mirror of https://github.com/mono/CppSharp.git
Browse Source
Fixes https://github.com/mono/CppSharp/issues/586. Signed-off-by: Dimitar Dobrev <dpldobrev@protonmail.com>const-wchar_t
2 changed files with 35 additions and 0 deletions
@ -0,0 +1,28 @@
@@ -0,0 +1,28 @@
|
||||
using System; |
||||
using System.Runtime.InteropServices; |
||||
using System.Security.Permissions; |
||||
using Microsoft.Win32.SafeHandles; |
||||
|
||||
namespace CppSharp.Runtime |
||||
{ |
||||
// https://stackoverflow.com/a/17563315/
|
||||
[SecurityPermission(SecurityAction.Demand, UnmanagedCode = true)] |
||||
public sealed class SafeUnmanagedMemoryHandle : SafeHandleZeroOrMinusOneIsInvalid |
||||
{ |
||||
public SafeUnmanagedMemoryHandle() : base(true) { } |
||||
|
||||
public SafeUnmanagedMemoryHandle(IntPtr preexistingHandle, bool ownsHandle) |
||||
: base(ownsHandle) => SetHandle(preexistingHandle); |
||||
|
||||
protected override bool ReleaseHandle() |
||||
{ |
||||
if (handle != IntPtr.Zero) |
||||
{ |
||||
Marshal.FreeHGlobal(handle); |
||||
handle = IntPtr.Zero; |
||||
return true; |
||||
} |
||||
return false; |
||||
} |
||||
} |
||||
} |
Loading…
Reference in new issue