Signed-off-by: Nikolay Sivov nsivov@codeweavers.com --- dlls/mfplat/queue.c | 2 ++ dlls/mfplat/tests/mfplat.c | 67 ++++++++++++++++++++++++++++++++++++++ 2 files changed, 69 insertions(+)
diff --git a/dlls/mfplat/queue.c b/dlls/mfplat/queue.c index 408526fec0..66f8588f82 100644 --- a/dlls/mfplat/queue.c +++ b/dlls/mfplat/queue.c @@ -649,6 +649,8 @@ static ULONG WINAPI async_result_Release(IMFAsyncResult *iface) IUnknown_Release(result->object); if (result->state) IUnknown_Release(result->state); + if (result->result.hEvent) + CloseHandle(result->result.hEvent); heap_free(result);
MFUnlockPlatform(); diff --git a/dlls/mfplat/tests/mfplat.c b/dlls/mfplat/tests/mfplat.c index 1bf7ebb41e..278112a9c5 100644 --- a/dlls/mfplat/tests/mfplat.c +++ b/dlls/mfplat/tests/mfplat.c @@ -907,7 +907,10 @@ static void test_MFCreateAsyncResult(void) IUnknown *state, *object; MFASYNCRESULT *data; ULONG refcount; + HANDLE event; + DWORD flags; HRESULT hr; + BOOL ret;
init_test_callback(&callback);
@@ -994,6 +997,35 @@ static void test_MFCreateAsyncResult(void) ok(!refcount, "Unexpected refcount %u\n.", refcount); refcount = IMFAsyncResult_Release(result); ok(!refcount, "Unexpected refcount %u\n.", refcount); + + /* Event handle is closed on release. */ + hr = MFCreateAsyncResult(NULL, NULL, NULL, &result); + ok(hr == S_OK, "Failed to create object, hr %#x.\n", hr); + + data = (MFASYNCRESULT *)result; + data->hEvent = event = CreateEventA(NULL, FALSE, FALSE, NULL); + ok(data->hEvent != NULL, "Failed to create event.\n"); + ret = GetHandleInformation(event, &flags); + ok(ret, "Failed to get handle info.\n"); + + refcount = IMFAsyncResult_Release(result); + ok(!refcount, "Unexpected refcount %u\n.", refcount); + ret = GetHandleInformation(event, &flags); + ok(!ret, "Expected handle to be closed.\n"); + + hr = MFCreateAsyncResult(NULL, &callback.IMFAsyncCallback_iface, NULL, &result); + ok(hr == S_OK, "Failed to create object, hr %#x.\n", hr); + + data = (MFASYNCRESULT *)result; + data->hEvent = event = CreateEventA(NULL, FALSE, FALSE, NULL); + ok(data->hEvent != NULL, "Failed to create event.\n"); + ret = GetHandleInformation(event, &flags); + ok(ret, "Failed to get handle info.\n"); + + refcount = IMFAsyncResult_Release(result); + ok(!refcount, "Unexpected refcount %u\n.", refcount); + ret = GetHandleInformation(event, &flags); + ok(!ret, "Expected handle to be closed.\n"); }
static void test_startup(void) @@ -1696,6 +1728,40 @@ static void test_system_time_source(void) IMFPresentationTimeSource_Release(time_source); }
+static void test_MFInvokeCallback(void) +{ + struct test_callback callback; + IMFAsyncResult *result; + MFASYNCRESULT *data; + ULONG refcount; + HRESULT hr; + DWORD ret; + + hr = MFStartup(MF_VERSION, MFSTARTUP_FULL); + ok(hr == S_OK, "Failed to start up, hr %#x.\n", hr); + + init_test_callback(&callback); + + hr = MFCreateAsyncResult(NULL, &callback.IMFAsyncCallback_iface, NULL, &result); + ok(hr == S_OK, "Failed to create object, hr %#x.\n", hr); + + data = (MFASYNCRESULT *)result; + data->hEvent = CreateEventA(NULL, FALSE, FALSE, NULL); + ok(data->hEvent != NULL, "Failed to create event.\n"); + + hr = MFInvokeCallback(result); + ok(hr == S_OK, "Failed to invoke, hr %#x.\n", hr); + + ret = WaitForSingleObject(data->hEvent, 100); + ok(ret == WAIT_TIMEOUT, "Expected timeout, ret %#x.\n", ret); + + refcount = IMFAsyncResult_Release(result); + ok(!refcount, "Unexpected refcount %u\n.", refcount); + + hr = MFShutdown(); + ok(hr == S_OK, "Failed to shut down, hr %#x.\n", hr); +} + START_TEST(mfplat) { CoInitialize(NULL); @@ -1723,6 +1789,7 @@ START_TEST(mfplat) test_event_queue(); test_presentation_descriptor(); test_system_time_source(); + test_MFInvokeCallback();
CoUninitialize(); }