[vlc-commits] va_surface: refcount the va_pool so it can be released with the last picture

Steve Lhomme git at videolan.org
Fri Oct 18 16:47:38 CEST 2019


vlc | branch: master | Steve Lhomme <robux4 at ycbcr.xyz> | Fri Oct 18 15:19:52 2019 +0200| [5249defb68df920bea75f31aee1045efe1e789e5] | committer: Steve Lhomme

va_surface: refcount the va_pool so it can be released with the last picture

The original creator is the one holding the first reference and release it via
va_pool_Close().

Fixes a leak of va_pool after va_pool_Close() is called.

> http://git.videolan.org/gitweb.cgi/vlc.git/?a=commit;h=5249defb68df920bea75f31aee1045efe1e789e5
---

 modules/codec/avcodec/va_surface.c | 20 +++++++++++++++++++-
 1 file changed, 19 insertions(+), 1 deletion(-)

diff --git a/modules/codec/avcodec/va_surface.c b/modules/codec/avcodec/va_surface.c
index 776da272c7..bf5e4a61e2 100644
--- a/modules/codec/avcodec/va_surface.c
+++ b/modules/codec/avcodec/va_surface.c
@@ -56,8 +56,23 @@ struct va_pool_t
     vlc_va_surface_t surface[MAX_SURFACE_COUNT];
 
     struct va_pool_cfg callbacks;
+
+    atomic_uintptr_t  poolrefs;
 };
 
+static void va_pool_AddRef(va_pool_t *va_pool)
+{
+    atomic_fetch_add(&va_pool->poolrefs, 1);
+}
+
+static void va_pool_Release(va_pool_t *va_pool)
+{
+    if (atomic_fetch_sub(&va_pool->poolrefs, 1) != 1)
+        return;
+
+    free(va_pool);
+}
+
 static void ReleasePoolSurfaces(va_pool_t *va_pool)
 {
     for (unsigned i = 0; i < va_pool->surface_count; i++)
@@ -170,7 +185,9 @@ unsigned va_surface_GetIndex(vlc_va_surface_t *surface)
 void va_pool_Close(vlc_va_t *va, va_pool_t *va_pool)
 {
     ReleasePoolSurfaces(va_pool);
-    va_pool->callbacks.pf_destroy_device(va);
+    void (*pf_destroy_device)(vlc_va_t *) = va_pool->callbacks.pf_destroy_device;
+    va_pool_Release(va_pool);
+    pf_destroy_device(va);
 }
 
 va_pool_t * va_pool_Create(vlc_va_t *va, const struct va_pool_cfg *cbs)
@@ -189,6 +206,7 @@ va_pool_t * va_pool_Create(vlc_va_t *va, const struct va_pool_cfg *cbs)
     msg_Dbg(va, "CreateDevice succeed");
 
     va_pool->surface_count = 0;
+    atomic_init(&va_pool->poolrefs, 1);
 
     return va_pool;
 }



More information about the vlc-commits mailing list