From 5e612aeb849b678b046e8249657f2fb70b055572 Mon Sep 17 00:00:00 2001 From: He Junyan Date: Fri, 7 Feb 2020 23:56:13 +0800 Subject: [PATCH] libs: videopool: fix a condition race for pool allocate. --- gst-libs/gst/vaapi/gstvaapivideopool.c | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/gst-libs/gst/vaapi/gstvaapivideopool.c b/gst-libs/gst/vaapi/gstvaapivideopool.c index faba367752..cb3ef3a6d4 100644 --- a/gst-libs/gst/vaapi/gstvaapivideopool.c +++ b/gst-libs/gst/vaapi/gstvaapivideopool.c @@ -179,6 +179,13 @@ gst_vaapi_video_pool_get_object_unlocked (GstVaapiVideoPool * pool) g_mutex_lock (&pool->mutex); if (!object) return NULL; + + /* Others already allocated a new one before us during we + release the mutex */ + if (pool->capacity && pool->used_count >= pool->capacity) { + gst_mini_object_unref (object); + return NULL; + } } ++pool->used_count;