mirror of
https://gitlab.freedesktop.org/pipewire/pipewire.git
synced 2025-11-03 09:01:54 -05:00
Plug some leaks
Add maxsize to bufferdata in case the memory size can be variable such as with encoded formats. Copy new size in the proxy.
This commit is contained in:
parent
9d4048e73a
commit
b208e8b690
15 changed files with 117 additions and 57 deletions
|
|
@ -24,11 +24,14 @@
|
|||
#include <sys/mman.h>
|
||||
#include <fcntl.h>
|
||||
#include <unistd.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
#include "memfd-wrappers.h"
|
||||
|
||||
#include <pinos/server/utils.h>
|
||||
|
||||
#undef USE_MEMFD
|
||||
|
||||
gboolean
|
||||
pinos_memblock_alloc (PinosMemblockFlags flags,
|
||||
gsize size,
|
||||
|
|
@ -41,19 +44,35 @@ pinos_memblock_alloc (PinosMemblockFlags flags,
|
|||
mem->size = size;
|
||||
|
||||
if (flags & PINOS_MEMBLOCK_FLAG_WITH_FD) {
|
||||
#ifdef USE_MEMFD
|
||||
mem->fd = memfd_create ("pinos-memfd", MFD_CLOEXEC | MFD_ALLOW_SEALING);
|
||||
if (mem->fd == -1) {
|
||||
fprintf (stderr, "Failed to create memfd: %s\n", strerror (errno));
|
||||
return FALSE;
|
||||
}
|
||||
#else
|
||||
char filename[] = "/dev/shm/spa-tmpfile.XXXXXX";
|
||||
mem->fd = mkostemp (filename, O_CLOEXEC);
|
||||
if (mem->fd == -1) {
|
||||
fprintf (stderr, "Failed to create temporary file: %s\n", strerror (errno));
|
||||
return FALSE;
|
||||
}
|
||||
unlink (filename);
|
||||
#endif
|
||||
|
||||
if (ftruncate (mem->fd, size) < 0) {
|
||||
g_warning ("Failed to truncate temporary file: %s", strerror (errno));
|
||||
close (mem->fd);
|
||||
return FALSE;
|
||||
}
|
||||
#ifdef USE_MEMFD
|
||||
if (flags & PINOS_MEMBLOCK_FLAG_SEAL) {
|
||||
unsigned int seals = F_SEAL_GROW | F_SEAL_SHRINK | F_SEAL_SEAL;
|
||||
if (fcntl (mem->fd, F_ADD_SEALS, seals) == -1) {
|
||||
g_warning ("Failed to add seals: %s", strerror (errno));
|
||||
}
|
||||
}
|
||||
#endif
|
||||
if (flags & PINOS_MEMBLOCK_FLAG_MAP_READWRITE) {
|
||||
int prot = 0;
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue