From 04d01b0f313e9b00633676ef98537d652a5da753 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=B6nke=20Ludwig?= Date: Thu, 20 Jun 2019 11:56:22 +0200 Subject: [PATCH] Handle terminated eventcore drivers gracefully when releasing handles. Instead of crashing, this now prints a warning message. See #135. --- source/vibe/core/internal/release.d | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/source/vibe/core/internal/release.d b/source/vibe/core/internal/release.d index 73e6323..33dac9c 100644 --- a/source/vibe/core/internal/release.d +++ b/source/vibe/core/internal/release.d @@ -8,6 +8,15 @@ void releaseHandle(string subsys, H)(H handle, shared(NativeEventDriver) drv) if (drv is (() @trusted => cast(shared)eventDriver)()) { __traits(getMember, eventDriver, subsys).releaseRef(handle); } else { + // if the owner driver has already been disposed, there is nothing we + // can do anymore + if (!drv.core) { + import vibe.core.log : logWarn; + logWarn("Leaking %s handle %s, because owner thread/driver has already terminated", + H.name, handle.value); + return; + } + // in case the destructor was called from a foreign thread, // perform the release in the owner thread drv.core.runInOwnerThread((h) {