From 15e5ecb3fca740894ddeeb94a8622e9a9f86ad13 Mon Sep 17 00:00:00 2001 From: Aron Heinecke Date: Wed, 14 Apr 2021 13:49:38 +0200 Subject: [PATCH] Fix leak on windows, porting #288 to v5 Signed-off-by: Aron Heinecke --- CHANGELOG.md | 2 ++ src/windows.rs | 5 ++++- 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 0334a2f9..295146d1 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -16,8 +16,10 @@ ## unreleased - FIX: Display proper error message when reaching inotify limits on linux [#285] +- FIX: Fix leaks on Windows [#298] [#285]: https://github.com/notify-rs/notify/pull/285 +[#298]: https://github.com/notify-rs/notify/pull/298 ## 5.0.0-pre.6 (2021-02-20) diff --git a/src/windows.rs b/src/windows.rs index 12359c7f..620b621e 100644 --- a/src/windows.rs +++ b/src/windows.rs @@ -235,7 +235,10 @@ fn stop_watch(ws: &WatchState, meta_tx: &Sender) { let ch = handleapi::CloseHandle(ws.dir_handle); // have to wait for it, otherwise we leak the memory allocated for there read request if cio != 0 && ch != 0 { - synchapi::WaitForSingleObjectEx(ws.complete_sem, INFINITE, TRUE); + while synchapi::WaitForSingleObjectEx(ws.complete_sem, INFINITE, TRUE) != WAIT_OBJECT_0 + { + // drain the apc queue, fix for https://github.com/notify-rs/notify/issues/287#issuecomment-801465550 + } } handleapi::CloseHandle(ws.complete_sem); }