From 83fba1b8091fdba45b77c1f045d90a7dfec488c3 Mon Sep 17 00:00:00 2001 From: Anton Onipko Date: Thu, 4 Jan 2024 21:28:49 +0200 Subject: [PATCH] Release AsyncOperationCompletedHandler (#208) windows: release AsyncOperationCompletedHandler --- adapter_windows.go | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/adapter_windows.go b/adapter_windows.go index 619ceaa..2211cab 100644 --- a/adapter_windows.go +++ b/adapter_windows.go @@ -40,10 +40,14 @@ func awaitAsyncOperation(asyncOperation *foundation.IAsyncOperation, genericPara // Wait until the async operation completes. waitChan := make(chan struct{}) - asyncOperation.SetCompleted(foundation.NewAsyncOperationCompletedHandler(ole.NewGUID(iid), func(instance *foundation.AsyncOperationCompletedHandler, asyncInfo *foundation.IAsyncOperation, asyncStatus foundation.AsyncStatus) { + handler := foundation.NewAsyncOperationCompletedHandler(ole.NewGUID(iid), func(instance *foundation.AsyncOperationCompletedHandler, asyncInfo *foundation.IAsyncOperation, asyncStatus foundation.AsyncStatus) { status = asyncStatus close(waitChan) - })) + }) + defer handler.Release() + + asyncOperation.SetCompleted(handler) + // Wait until async operation has stopped, and finish. <-waitChan