[vlc-commits] [Git][videolan/vlc][master] va_surface: fix potential double use of a buffer

Felix Paul Kühne (@fkuehne) gitlab at videolan.org
Thu May 12 12:56:42 UTC 2022



Felix Paul Kühne pushed to branch master at VideoLAN / VLC


Commits:
35886895 by Steve Lhomme at 2022-05-12T12:42:32+00:00
va_surface: fix potential double use of a buffer

Substracting 1 to refcount first, means it goes back to unused state
temporarily. It may be picked by another thread as well before calling
atomic_fetch_sub().

In the end we don't need the -1,+1 it's already in the "used once" state (2)
after the atomic_compare_exchange() call.

- - - - -


1 changed file:

- modules/codec/avcodec/va_surface.c


Changes:

=====================================
modules/codec/avcodec/va_surface.c
=====================================
@@ -122,13 +122,10 @@ static vlc_va_surface_t *GetSurface(va_pool_t *va_pool)
 {
     for (unsigned i = 0; i < va_pool->surface_count; i++) {
         vlc_va_surface_t *surface = &va_pool->surface[i];
-        uintptr_t expected = 1;
+        uintptr_t expected = 1; // exists but unused
 
         if (atomic_compare_exchange_strong(&surface->refcount, &expected, 2))
         {
-            /* the copy should have added an extra reference */
-            atomic_fetch_sub(&surface->refcount, 1);
-            va_surface_AddRef(surface);
             return surface;
         }
     }
@@ -139,7 +136,7 @@ vlc_va_surface_t *va_pool_Get(va_pool_t *va_pool)
 {
     vlc_va_surface_t *surface;
 
-    if (va_pool->surface_count == 0)
+    if (unlikely(va_pool->surface_count == 0))
         return NULL;
 
     vlc_sem_wait(&va_pool->available_surfaces);



View it on GitLab: https://code.videolan.org/videolan/vlc/-/commit/3588689553a9063284d63681fc71da796c233738

-- 
View it on GitLab: https://code.videolan.org/videolan/vlc/-/commit/3588689553a9063284d63681fc71da796c233738
You're receiving this email because of your account on code.videolan.org.


VideoLAN code repository instance


More information about the vlc-commits mailing list