mirror of
https://gitlab.freedesktop.org/gstreamer/gstreamer.git
synced 2024-11-29 21:21:12 +00:00
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: <https://gitlab.freedesktop.org/gstreamer/gstreamer/-/merge_requests/6104>
This commit is contained in:
parent
f0b8a33f10
commit
1ef7e9be73
1 changed files with 5 additions and 4 deletions
|
@ -113,7 +113,7 @@ gst_shm_allocator_alloc (GstAllocator * allocator, gsize size,
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
mem = gst_fd_allocator_alloc (allocator, fd, size,
|
mem = gst_fd_allocator_alloc (allocator, fd, maxsize,
|
||||||
GST_FD_MEMORY_FLAG_KEEP_MAPPED);
|
GST_FD_MEMORY_FLAG_KEEP_MAPPED);
|
||||||
if (G_UNLIKELY (!mem)) {
|
if (G_UNLIKELY (!mem)) {
|
||||||
GST_ERROR_OBJECT (self, "GstFdMemory allocation failed");
|
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 */
|
/* See _sysmem_new_block() for details */
|
||||||
guint8 *data = info.data;
|
guint8 *data = info.data;
|
||||||
gsize aoffset;
|
gsize aoffset;
|
||||||
|
gsize asize = maxsize;
|
||||||
if ((aoffset = ((guintptr) data & align))) {
|
if ((aoffset = ((guintptr) data & align))) {
|
||||||
aoffset = (align + 1) - aoffset;
|
aoffset = (align + 1) - aoffset;
|
||||||
data += aoffset;
|
data += aoffset;
|
||||||
maxsize -= aoffset;
|
asize = maxsize - aoffset;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (params->prefix && (params->flags & GST_MEMORY_FLAG_ZERO_PREFIXED))
|
if (params->prefix && (params->flags & GST_MEMORY_FLAG_ZERO_PREFIXED))
|
||||||
memset (data, 0, params->prefix);
|
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))
|
if (padding && (params->flags & GST_MEMORY_FLAG_ZERO_PADDED))
|
||||||
memset (data + params->prefix + size, 0, padding);
|
memset (data + params->prefix + size, 0, padding);
|
||||||
|
|
||||||
mem->align = align;
|
mem->align = align;
|
||||||
mem->maxsize = maxsize;
|
mem->size = size;
|
||||||
mem->offset = params->prefix + aoffset;
|
mem->offset = params->prefix + aoffset;
|
||||||
|
|
||||||
gst_memory_unmap (mem, &info);
|
gst_memory_unmap (mem, &info);
|
||||||
|
|
Loading…
Reference in a new issue