From 1ef7e9be73955efb513e377dbd198511b1dcbcbc Mon Sep 17 00:00:00 2001 From: Damian Hobson-Garcia Date: Thu, 8 Feb 2024 21:51:38 -0500 Subject: [PATCH] GstShmAllocator: Map/unmap full buffer when padding is added When allocating buffers with alignment parameters specified, it may be necessary to overallocate memory to adjust to the requested alignment. Previously the padding length was not included in the mmaped buffer size, leaving unmapped bytes at the end of the buffer. This caused intermittent SEGV faults and valgrind failures when running the wayland_threads example. Part-of: --- .../gst-libs/gst/allocators/gstshmallocator.c | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/subprojects/gst-plugins-base/gst-libs/gst/allocators/gstshmallocator.c b/subprojects/gst-plugins-base/gst-libs/gst/allocators/gstshmallocator.c index 8abe02e21c..4210accc9e 100644 --- a/subprojects/gst-plugins-base/gst-libs/gst/allocators/gstshmallocator.c +++ b/subprojects/gst-plugins-base/gst-libs/gst/allocators/gstshmallocator.c @@ -113,7 +113,7 @@ gst_shm_allocator_alloc (GstAllocator * allocator, gsize size, return NULL; } - mem = gst_fd_allocator_alloc (allocator, fd, size, + mem = gst_fd_allocator_alloc (allocator, fd, maxsize, GST_FD_MEMORY_FLAG_KEEP_MAPPED); if (G_UNLIKELY (!mem)) { GST_ERROR_OBJECT (self, "GstFdMemory allocation failed"); @@ -131,21 +131,22 @@ gst_shm_allocator_alloc (GstAllocator * allocator, gsize size, /* See _sysmem_new_block() for details */ guint8 *data = info.data; gsize aoffset; + gsize asize = maxsize; if ((aoffset = ((guintptr) data & align))) { aoffset = (align + 1) - aoffset; data += aoffset; - maxsize -= aoffset; + asize = maxsize - aoffset; } if (params->prefix && (params->flags & GST_MEMORY_FLAG_ZERO_PREFIXED)) memset (data, 0, params->prefix); - gsize padding = maxsize - (params->prefix + size); + gsize padding = asize - (params->prefix + size); if (padding && (params->flags & GST_MEMORY_FLAG_ZERO_PADDED)) memset (data + params->prefix + size, 0, padding); mem->align = align; - mem->maxsize = maxsize; + mem->size = size; mem->offset = params->prefix + aoffset; gst_memory_unmap (mem, &info);