Merge pull request #118 from vibe-d/fix_polling_watcher_crash

Fix possible access of freed directory watcher entries.
This commit is contained in:
Sönke Ludwig 2019-08-20 18:40:16 +02:00 committed by GitHub
commit fbcdf98093
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -475,12 +475,11 @@ final class PollEventDriverWatchers(Events : EventDriverEvents) : EventDriverWat
scan(null, generate_changes, new_entries, added, ec); scan(null, generate_changes, new_entries, added, ec);
// detect all roots of removed sub trees
foreach (e; m_entries.byKeyValue) { foreach (e; m_entries.byKeyValue) {
if (!e.key.parent || Key(e.key.parent.parent, e.key.parent.name) !in m_entries) { if (!e.key.parent || Key(e.key.parent.parent, e.key.parent.name) !in m_entries) {
if (generate_changes) if (generate_changes)
addChange(FileChangeKind.removed, e.key, e.value.isDir); addChange(FileChangeKind.removed, e.key, e.value.isDir);
try freeT(e.value);
catch (Exception e) assert(false, e.msg);
} }
} }
@ -489,6 +488,12 @@ final class PollEventDriverWatchers(Events : EventDriverEvents) : EventDriverWat
swap(m_entries, new_entries); swap(m_entries, new_entries);
m_entryCount = ec; m_entryCount = ec;
// clear all left-over entries (delted directly or indirectly)
foreach (e; new_entries.byValue) {
try freeT(e);
catch (Exception e) assert(false, e.msg);
}
} }
private void scan(Entry parent, bool generate_changes, ref Entry[Key] new_entries, ref Entry[] added, ref size_t ec) private void scan(Entry parent, bool generate_changes, ref Entry[Key] new_entries, ref Entry[] added, ref size_t ec)