[PATCH 2/5] evr/allocator: Fix reference counting for returned samples.

Nikolay Sivov nsivov at codeweavers.com
Thu Nov 12 04:36:36 CST 2020


Signed-off-by: Nikolay Sivov <nsivov at codeweavers.com>
---
 dlls/evr/sample.c    | 6 ++++--
 dlls/evr/tests/evr.c | 7 +++----
 2 files changed, 7 insertions(+), 6 deletions(-)

diff --git a/dlls/evr/sample.c b/dlls/evr/sample.c
index e84d7450c7f..7764ec945d2 100644
--- a/dlls/evr/sample.c
+++ b/dlls/evr/sample.c
@@ -459,7 +459,6 @@ static void sample_allocator_release_samples(struct sample_allocator *allocator)
     LIST_FOR_EACH_ENTRY_SAFE(iter, iter2, &allocator->used_samples, struct queued_sample, entry)
     {
         list_remove(&iter->entry);
-        IMFSample_Release(iter->sample);
         heap_free(iter);
     }
 }
@@ -676,8 +675,10 @@ static HRESULT WINAPI sample_allocator_AllocateSample(IMFVideoSampleAllocator *i
             list_add_tail(&allocator->used_samples, head);
             allocator->free_sample_count--;
 
+            /* Reference counter is not increased when sample is returned, so next release could trigger
+               tracking condition. This is balanced by incremented reference counter when sample is returned
+               back to the free list. */
             *out = sample;
-            IMFSample_AddRef(*out);
         }
     }
 
@@ -816,6 +817,7 @@ static HRESULT WINAPI sample_allocator_tracking_callback_Invoke(IMFAsyncCallback
         {
             list_remove(&iter->entry);
             list_add_tail(&allocator->free_samples, &iter->entry);
+            IMFSample_AddRef(iter->sample);
             allocator->free_sample_count++;
             break;
         }
diff --git a/dlls/evr/tests/evr.c b/dlls/evr/tests/evr.c
index a1d7b7109d9..b8a16fc7cc9 100644
--- a/dlls/evr/tests/evr.c
+++ b/dlls/evr/tests/evr.c
@@ -1326,13 +1326,13 @@ static void test_MFCreateVideoSampleAllocator(void)
     IDirect3DSurface9 *surface;
     IDirect3DDevice9 *device;
     IMFMediaBuffer *buffer;
+    LONG refcount, count;
     unsigned int token;
     IMFGetService *gs;
     IDirect3D9 *d3d;
     IUnknown *unk;
     HWND window;
     HRESULT hr;
-    LONG count;
     BYTE *data;
 
     hr = MFCreateVideoSampleAllocator(&IID_IUnknown, (void **)&unk);
@@ -1397,7 +1397,7 @@ todo_wine
     sample = NULL;
     hr = IMFVideoSampleAllocator_AllocateSample(allocator, &sample);
     ok(hr == S_OK, "Unexpected hr %#x.\n", hr);
-    ok(get_refcount(sample) == 3, "Unexpected refcount %u.\n", get_refcount(sample));
+    refcount = get_refcount(sample);
 
     hr = IMFVideoSampleAllocator_AllocateSample(allocator, &sample2);
     ok(hr == MF_E_SAMPLEALLOCATOR_EMPTY, "Unexpected hr %#x.\n", hr);
@@ -1405,8 +1405,7 @@ todo_wine
     /* Reinitialize with active sample. */
     hr = IMFVideoSampleAllocator_InitializeSampleAllocator(allocator, 4, video_type);
     ok(hr == S_OK, "Unexpected hr %#x.\n", hr);
-todo_wine
-    ok(get_refcount(sample) == 3, "Unexpected refcount %u.\n", get_refcount(sample));
+    ok(refcount == get_refcount(sample), "Unexpected refcount %u.\n", get_refcount(sample));
 
     hr = IMFVideoSampleAllocatorCallback_GetFreeSampleCount(allocator_cb, &count);
     ok(hr == S_OK, "Unexpected hr %#x.\n", hr);
-- 
2.28.0




More information about the wine-devel mailing list