diff --git a/subprojects/gst-plugins-bad/sys/kms/gstkmsallocator.c b/subprojects/gst-plugins-bad/sys/kms/gstkmsallocator.c index fefea31f4f..3ec2fdb32d 100644 --- a/subprojects/gst-plugins-bad/sys/kms/gstkmsallocator.c +++ b/subprojects/gst-plugins-bad/sys/kms/gstkmsallocator.c @@ -427,7 +427,7 @@ gst_kms_allocator_dmabuf_import (GstAllocator * allocator, gint * prime_fds, GstKMSAllocator *alloc; GstKMSMemory *kmsmem; GstMemory *mem; - gint i, ret; + gint i, j, ret; guint32 gem_handle[4] = { 0, }; g_return_val_if_fail (n_planes <= GST_VIDEO_MAX_PLANES, FALSE); @@ -456,6 +456,14 @@ done: if (!gem_handle[i]) continue; + /* Do not close the same handle twice. */ + for (j = 0; j < i; j++) { + if (gem_handle[j] == gem_handle[i]) + break; + } + if (j < i) + continue; + err = drmIoctl (alloc->priv->fd, DRM_IOCTL_GEM_CLOSE, &arg); if (err) GST_WARNING_OBJECT (allocator,