Skip to content
This repository was archived by the owner on Dec 18, 2018. It is now read-only.

Fix NPE issue where UvShutdownReq being garbage collected before the shutdown callback executed #128

Merged
merged 1 commit into from
Jul 14, 2015
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.

using System;
using System.Runtime.InteropServices;

namespace Microsoft.AspNet.Server.Kestrel.Networking
{
Expand All @@ -14,6 +15,7 @@ public class UvShutdownReq : UvReq

Action<UvShutdownReq, int, object> _callback;
object _state;
GCHandle _pin;

public void Init(UvLoopHandle loop)
{
Expand All @@ -27,12 +29,14 @@ public void Shutdown(UvStreamHandle handle, Action<UvShutdownReq, int, object> c
{
_callback = callback;
_state = state;
_pin = GCHandle.Alloc(this, GCHandleType.Normal);
_uv.shutdown(this, handle, _uv_shutdown_cb);
}

private static void UvShutdownCb(IntPtr ptr, int status)
{
var req = FromIntPtr<UvShutdownReq>(ptr);
req._pin.Free();
req._callback(req, status, req._state);
req._callback = null;
req._state = null;
Expand Down