Skip to content

Commit

Permalink
Avoid access of possible dangling driver references. Fixes #978.
Browse files Browse the repository at this point in the history
This is a two-step fix: destroy() is used instead of delete for the event driver and the driver core, so that there can not be any dangling references left. Additionally, the Timer struct now only tries to release the timer counter when the library has not yet been shut down. This avoids triggering an assertion, which in turn results in the InvalidMemoryOperationError in #978.
  • Loading branch information
s-ludwig committed Feb 11, 2015
1 parent ab6bdab commit 7150c2d
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 4 deletions.
7 changes: 4 additions & 3 deletions source/vibe/core/core.d
Original file line number Diff line number Diff line change
Expand Up @@ -726,7 +726,7 @@ struct Timer {
~this()
{
debug assert(m_magicNumber == 0x4d34f916);
if (m_driver) m_driver.releaseTimer(m_id);
if (m_driver && s_core) m_driver.releaseTimer(m_id);
}

/// True if the timer is yet to fire.
Expand Down Expand Up @@ -1309,7 +1309,8 @@ shared static ~this()
if (!s_yieldedTasks.empty) tasks_left = true;
if (tasks_left) logWarn("There are still tasks running at exit.");

delete s_core;
destroy(s_core);
s_core = null;
}

// per thread setup
Expand All @@ -1319,7 +1320,7 @@ static this()
// object.Exception@src/rt/minfo.d(162): Aborting: Cycle detected between modules with ctors/dtors:
// vibe.core.core -> vibe.core.drivers.native -> vibe.core.drivers.libasync -> vibe.core.core
if (Thread.getThis().isDaemon && Thread.getThis().name == "CmdProcessor") return;

assert(s_core !is null);

auto thisthr = Thread.getThis();
Expand Down
2 changes: 1 addition & 1 deletion source/vibe/core/driver.d
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ package void setupEventDriver(DriverCore core_)
package void deleteEventDriver()
{
s_driver.dispose();
delete s_driver;
destroy(s_driver);
s_driver = null;
}

Expand Down

0 comments on commit 7150c2d

Please sign in to comment.