Module: wine
Branch: master
Commit: b1807751219e256867eaac5cc4d8b97a5482978f
URL: https://source.winehq.org/git/wine.git/?a=commit;h=b1807751219e256867eaac5c…
Author: Giovanni Mascellani <gmascellani(a)codeweavers.com>
Date: Tue May 3 15:06:43 2022 +0200
mfplat: Avoid a race condition when releasing a tracked sample.
Right now, if the same tracked sample is released at the same time
from two different threads it might happen that neither of them calls
the callback, because they might go through the critical section at
the same time (while neither has decremented the reference count yet).
Signed-off-by: Giovanni Mascellani <gmascellani(a)codeweavers.com>
Signed-off-by: Alexandre Julliard <julliard(a)winehq.org>
---
dlls/mfplat/sample.c | 6 ++----
1 file changed, 2 insertions(+), 4 deletions(-)
diff --git a/dlls/mfplat/sample.c b/dlls/mfplat/sample.c
index 8ef80eb5f24..ed39b5f7297 100644
--- a/dlls/mfplat/sample.c
+++ b/dlls/mfplat/sample.c
@@ -182,11 +182,11 @@ static ULONG WINAPI sample_Release(IMFSample *iface)
static ULONG WINAPI sample_tracked_Release(IMFSample *iface)
{
struct sample *sample = impl_from_IMFSample(iface);
- ULONG refcount;
+ ULONG refcount = InterlockedDecrement(&sample->attributes.ref);
HRESULT hr;
EnterCriticalSection(&sample->attributes.cs);
- if (sample->tracked_result && sample->tracked_refcount == (sample->attributes.ref - 1))
+ if (sample->tracked_result && sample->tracked_refcount == refcount)
{
IRtwqAsyncResult *tracked_result = sample->tracked_result;
sample->tracked_result = NULL;
@@ -199,8 +199,6 @@ static ULONG WINAPI sample_tracked_Release(IMFSample *iface)
}
LeaveCriticalSection(&sample->attributes.cs);
- refcount = InterlockedDecrement(&sample->attributes.ref);
-
TRACE("%p, refcount %lu.\n", iface, refcount);
if (!refcount)