Module: wine Branch: stable Commit: 7d74dd91bfb3582cebb6c87e409edf6cb124b17e URL: https://gitlab.winehq.org/wine/wine/-/commit/7d74dd91bfb3582cebb6c87e409edf6...
Author: Nikolay Sivov nsivov@codeweavers.com Date: Tue May 10 19:16:17 2022 +0300
evr/sample: Avoid a race condition when releasing a tracked sample.
Same as b1807751219e256867eaac5cc4d8b97a5482978f.
Signed-off-by: Nikolay Sivov nsivov@codeweavers.com Signed-off-by: Alexandre Julliard julliard@winehq.org (cherry picked from commit ce71f5a05f226b3f68328d4632cd78ac9440d073) Signed-off-by: Michael Stefaniuc mstefani@winehq.org
---
dlls/evr/sample.c | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-)
diff --git a/dlls/evr/sample.c b/dlls/evr/sample.c index cbba384e181..7530cee07e2 100644 --- a/dlls/evr/sample.c +++ b/dlls/evr/sample.c @@ -920,19 +920,21 @@ static ULONG WINAPI video_sample_AddRef(IMFSample *iface) static ULONG WINAPI video_sample_Release(IMFSample *iface) { struct video_sample *sample = impl_from_IMFSample(iface); - ULONG refcount; + ULONG refcount = InterlockedDecrement(&sample->refcount); + IMFAsyncResult *tracked_result = NULL;
IMFSample_LockStore(sample->sample); - if (sample->tracked_result && sample->tracked_refcount == (sample->refcount - 1)) + if (sample->tracked_result && sample->tracked_refcount == refcount) { - video_sample_tracking_thread_invoke(sample->tracked_result); - IMFAsyncResult_Release(sample->tracked_result); + tracked_result = sample->tracked_result; + video_sample_tracking_thread_invoke(tracked_result); sample->tracked_result = NULL; sample->tracked_refcount = 0; } IMFSample_UnlockStore(sample->sample);
- refcount = InterlockedDecrement(&sample->refcount); + if (tracked_result) + IMFAsyncResult_Release(tracked_result);
TRACE("%p, refcount %u.\n", iface, refcount);