Fix UvLoopHandle.ReleaseHandle on linux

Libuv.loop_close can clear the GCHandle pointer on linux
This commit is contained in:
Stephen Halter 2015-06-17 17:53:56 -07:00
parent 5c6a53c491
commit 29098d6383
2 changed files with 11 additions and 3 deletions

View File

@ -28,17 +28,20 @@ namespace Microsoft.AspNet.Server.Kestrel.Networking
_uv.stop(this); _uv.stop(this);
} }
protected override bool ReleaseHandle() unsafe protected override bool ReleaseHandle()
{ {
var memory = this.handle; var memory = this.handle;
if (memory != IntPtr.Zero) if (memory != IntPtr.Zero)
{ {
// loop_close clears the gcHandlePtr
var gcHandlePtr = *(IntPtr*)memory;
_uv.loop_close(this); _uv.loop_close(this);
handle = IntPtr.Zero; handle = IntPtr.Zero;
DestroyMemory(memory);
DestroyMemory(memory, gcHandlePtr);
} }
return true; return true;
} }
} }
} }

View File

@ -54,6 +54,11 @@ namespace Microsoft.AspNet.Server.Kestrel.Networking
unsafe protected static void DestroyMemory(IntPtr memory) unsafe protected static void DestroyMemory(IntPtr memory)
{ {
var gcHandlePtr = *(IntPtr*)memory; var gcHandlePtr = *(IntPtr*)memory;
DestroyMemory(memory, gcHandlePtr);
}
unsafe protected static void DestroyMemory(IntPtr memory, IntPtr gcHandlePtr)
{
if (gcHandlePtr != IntPtr.Zero) if (gcHandlePtr != IntPtr.Zero)
{ {
var gcHandle = GCHandle.FromIntPtr(gcHandlePtr); var gcHandle = GCHandle.FromIntPtr(gcHandlePtr);