Fix cleanup code for directory watchers in the WinAPI driver.
- Fixes an assertion triggered by accessing a file field in releaseRef - Fixed a potential leak of file system watcher handles when calling releaseRef from inside the supplied callback - this was the reason why the fixed assertion error wasn't triggered by the test code
This commit is contained in:
parent
574de0760d
commit
53bb8eeead
|
@ -82,7 +82,7 @@ final class WinAPIEventDriverWatchers : EventDriverWatchers {
|
||||||
catch (Exception e) assert(false, "Freeing directory watcher buffer failed.");
|
catch (Exception e) assert(false, "Freeing directory watcher buffer failed.");
|
||||||
} ();
|
} ();
|
||||||
slot.watcher.buffer = null;
|
slot.watcher.buffer = null;
|
||||||
core.discardEvents(&slot.watcher.overlapped, &slot.file.write.overlapped);
|
core.discardEvents(&slot.watcher.overlapped);
|
||||||
core.freeSlot(handle);
|
core.freeSlot(handle);
|
||||||
}))
|
}))
|
||||||
{
|
{
|
||||||
|
@ -159,10 +159,13 @@ final class WinAPIEventDriverWatchers : EventDriverWatchers {
|
||||||
catch (Exception e) {} // FIXME: can happen if the base path is relative and the CWD has changed
|
catch (Exception e) {} // FIXME: can happen if the base path is relative and the CWD has changed
|
||||||
if (ch.kind != FileChangeKind.modified || !ch.isDirectory)
|
if (ch.kind != FileChangeKind.modified || !ch.isDirectory)
|
||||||
slot.callback(id, ch);
|
slot.callback(id, ch);
|
||||||
if (fni.NextEntryOffset == 0) break;
|
if (fni.NextEntryOffset == 0 || !slot.callback) break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (slot.callback)
|
||||||
triggerRead(handle, *slot);
|
triggerRead(handle, *slot);
|
||||||
|
else if (gslot.refCount == 1)
|
||||||
|
doReleaseRef(handle);
|
||||||
}
|
}
|
||||||
|
|
||||||
private static bool triggerRead(HANDLE handle, ref WatcherSlot slot)
|
private static bool triggerRead(HANDLE handle, ref WatcherSlot slot)
|
||||||
|
|
Loading…
Reference in a new issue