From 3e7969cefe89ec38e9ed64658479ca04cf890515 Mon Sep 17 00:00:00 2001 From: Ben Adams Date: Wed, 4 Nov 2015 22:44:30 +0000 Subject: [PATCH] Move handle creation to constructor --- .../Http/ListenerSecondary.cs | 13 ++++--------- 1 file changed, 4 insertions(+), 9 deletions(-) diff --git a/src/Microsoft.AspNet.Server.Kestrel/Http/ListenerSecondary.cs b/src/Microsoft.AspNet.Server.Kestrel/Http/ListenerSecondary.cs index 79e1ab89c1..d74c664e62 100644 --- a/src/Microsoft.AspNet.Server.Kestrel/Http/ListenerSecondary.cs +++ b/src/Microsoft.AspNet.Server.Kestrel/Http/ListenerSecondary.cs @@ -18,11 +18,13 @@ namespace Microsoft.AspNet.Server.Kestrel.Http public abstract class ListenerSecondary : ListenerContext, IDisposable { private string _pipeName; - private IntPtr _ptr = IntPtr.Zero; + private IntPtr _ptr; private Libuv.uv_buf_t _buf; protected ListenerSecondary(ServiceContext serviceContext) : base(serviceContext) { + _ptr = Marshal.AllocHGlobal(4); + _buf = Thread.Loop.Libuv.buf_init(_ptr, 4); } UvPipeHandle DispatchPipe { get; set; } @@ -88,9 +90,6 @@ namespace Microsoft.AspNet.Server.Kestrel.Http try { - _ptr = Marshal.AllocHGlobal(4); - _buf = Thread.Loop.Libuv.buf_init(_ptr, 4); - DispatchPipe.ReadStart( (handle, status2, state) => ((ListenerSecondary)state)._buf, (handle, status2, state) => @@ -153,11 +152,7 @@ namespace Microsoft.AspNet.Server.Kestrel.Http public void Dispose() { - if (_ptr != IntPtr.Zero) - { - Marshal.FreeHGlobal(_ptr); - _ptr = IntPtr.Zero; - } + Marshal.FreeHGlobal(_ptr); // Ensure the event loop is still running. // If the event loop isn't running and we try to wait on this Post