From 0fd76c2848baadf645e69241faef63298b90c5f2 Mon Sep 17 00:00:00 2001 From: Nicolas Dufresne Date: Sun, 4 Feb 2024 10:12:22 +0100 Subject: [PATCH] allocators: drm-dumb: Fix non-thread safe dmabuf allocator creation If the allocation function get called from multiple threads at the same time, multiple allocators may get created but only one get saved. Leading to other allocators to be leaked. Simply create it once in the instance initialization. Fixes: #2456 Part-of: --- .../gst-plugins-base/gst-libs/gst/allocators/gstdrmdumb.c | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/subprojects/gst-plugins-base/gst-libs/gst/allocators/gstdrmdumb.c b/subprojects/gst-plugins-base/gst-libs/gst/allocators/gstdrmdumb.c index 9798d73bcb..1cf3034ac7 100644 --- a/subprojects/gst-plugins-base/gst-libs/gst/allocators/gstdrmdumb.c +++ b/subprojects/gst-plugins-base/gst-libs/gst/allocators/gstdrmdumb.c @@ -156,9 +156,6 @@ gst_drm_dumb_memory_export_dmabuf (GstMemory * mem) if (ret) goto export_fd_failed; - if (G_UNLIKELY (alloc->dmabuf_alloc == NULL)) - alloc->dmabuf_alloc = gst_dmabuf_allocator_new (); - dmamem = gst_dmabuf_allocator_alloc (alloc->dmabuf_alloc, prime_fd, gst_memory_get_sizes (mem, NULL, NULL)); @@ -452,8 +449,7 @@ gst_drm_dumb_allocator_finalize (GObject * obj) { GstDRMDumbAllocator *alloc = GST_DRM_DUMB_ALLOCATOR (obj); - if (alloc->dmabuf_alloc) - gst_object_unref (alloc->dmabuf_alloc); + gst_object_unref (alloc->dmabuf_alloc); g_free (alloc->drm_device_path); alloc->drm_device_path = NULL; @@ -581,6 +577,7 @@ gst_drm_dumb_allocator_init (GstDRMDumbAllocator * alloc) alloc->drm_fd = -1; alloc->drm_device_path = NULL; + alloc->dmabuf_alloc = gst_dmabuf_allocator_new (); base_alloc->mem_type = GST_DRM_DUMB_MEMORY_TYPE; base_alloc->mem_map = gst_drm_dumb_memory_map;