From 4d0037687345e3b14514d1f8e7464f50fd13a4c8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=B6nke=20Ludwig?= Date: Thu, 23 Nov 2017 22:56:25 +0100 Subject: [PATCH] Ensure proper reference count for created Posix events. --- source/eventcore/drivers/posix/events.d | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/source/eventcore/drivers/posix/events.d b/source/eventcore/drivers/posix/events.d index e6901c8..08c48a2 100644 --- a/source/eventcore/drivers/posix/events.d +++ b/source/eventcore/drivers/posix/events.d @@ -50,6 +50,7 @@ final class PosixEventDriverEvents(Loop : PosixEventLoop, Sockets : EventDriverS m_loop.registerFD(id, EventMask.read); m_loop.setNotifyCallback!(EventType.read)(id, &onEvent); releaseRef(id); // setNotifyCallback increments the reference count, but we need a value of 1 upon return + assert(getRC(id) == 1); return id; } else { auto addr = new InternetAddress(0x7F000001, 0); @@ -58,7 +59,9 @@ final class PosixEventDriverEvents(Loop : PosixEventLoop, Sockets : EventDriverS m_sockets.receive(s, m_buf, IOMode.once, &onSocketData); m_events[s] = EventSlot(new ConsumableQueue!EventCallback, false, is_internal); // FIXME: avoid dynamic memory allocation m_sockets.releaseRef(s); // receive() increments the reference count, but we need a value of 1 upon return - return cast(EventID)s; + auto id = cast(EventID)s; + assert(getRC(id) == 1); + return id; } }