evr/sample: Avoid a race condition when releasing a tracked sample.

Same as b180775121.

Signed-off-by: Nikolay Sivov <nsivov@codeweavers.com>
Signed-off-by: Alexandre Julliard <julliard@winehq.org>
This commit is contained in:
Nikolay Sivov 2022-05-10 19:16:17 +03:00 committed by Alexandre Julliard
parent 1d7d3f58d6
commit ce71f5a05f
1 changed files with 7 additions and 5 deletions

View File

@ -920,19 +920,21 @@ static ULONG WINAPI video_sample_AddRef(IMFSample *iface)
static ULONG WINAPI video_sample_Release(IMFSample *iface) static ULONG WINAPI video_sample_Release(IMFSample *iface)
{ {
struct video_sample *sample = impl_from_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); 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); tracked_result = sample->tracked_result;
IMFAsyncResult_Release(sample->tracked_result); video_sample_tracking_thread_invoke(tracked_result);
sample->tracked_result = NULL; sample->tracked_result = NULL;
sample->tracked_refcount = 0; sample->tracked_refcount = 0;
} }
IMFSample_UnlockStore(sample->sample); IMFSample_UnlockStore(sample->sample);
refcount = InterlockedDecrement(&sample->refcount); if (tracked_result)
IMFAsyncResult_Release(tracked_result);
TRACE("%p, refcount %lu.\n", iface, refcount); TRACE("%p, refcount %lu.\n", iface, refcount);