mirror of
https://gitlab.freedesktop.org/pipewire/pipewire.git
synced 2025-11-08 13:30:08 -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
|
|
@ -491,6 +491,7 @@ do_allocation (PinosLink *this, SpaNodeState in_state, SpaNodeState out_state)
|
|||
this->input->buffers = priv->buffers;
|
||||
this->input->n_buffers = priv->n_buffers;
|
||||
this->input->allocated = TRUE;
|
||||
this->input->buffer_mem = priv->buffer_mem;
|
||||
priv->allocated = FALSE;
|
||||
g_debug ("allocated %d buffers %p from input port", priv->n_buffers, priv->buffers);
|
||||
}
|
||||
|
|
@ -507,6 +508,7 @@ do_allocation (PinosLink *this, SpaNodeState in_state, SpaNodeState out_state)
|
|||
this->output->buffers = priv->buffers;
|
||||
this->output->n_buffers = priv->n_buffers;
|
||||
this->output->allocated = TRUE;
|
||||
this->output->buffer_mem = priv->buffer_mem;
|
||||
priv->allocated = FALSE;
|
||||
g_debug ("allocated %d buffers %p from output port", priv->n_buffers, priv->buffers);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -29,6 +29,7 @@ typedef struct _PinosLinkClass PinosLinkClass;
|
|||
typedef struct _PinosLinkPrivate PinosLinkPrivate;
|
||||
|
||||
#include <pinos/server/daemon.h>
|
||||
#include <pinos/server/utils.h>
|
||||
#include <spa/include/spa/ringbuffer.h>
|
||||
|
||||
#define PINOS_TYPE_LINK (pinos_link_get_type ())
|
||||
|
|
@ -41,11 +42,12 @@ typedef struct _PinosLinkPrivate PinosLinkPrivate;
|
|||
#define PINOS_LINK_CLASS_CAST(klass)((PinosLinkClass*)(klass))
|
||||
|
||||
typedef struct {
|
||||
PinosNode *node;
|
||||
uint32_t port;
|
||||
gboolean allocated;
|
||||
SpaBuffer **buffers;
|
||||
guint n_buffers;
|
||||
PinosNode *node;
|
||||
uint32_t port;
|
||||
gboolean allocated;
|
||||
PinosMemblock buffer_mem;
|
||||
SpaBuffer **buffers;
|
||||
guint n_buffers;
|
||||
} PinosPort;
|
||||
|
||||
/**
|
||||
|
|
|
|||
|
|
@ -285,6 +285,8 @@ suspend_node (PinosNode *this)
|
|||
g_warning ("error unset format output: %d", res);
|
||||
p->port.buffers = NULL;
|
||||
p->port.n_buffers = 0;
|
||||
if (p->port.allocated)
|
||||
pinos_memblock_free (&p->port.buffer_mem);
|
||||
p->port.allocated = FALSE;
|
||||
}
|
||||
for (walk = priv->output_ports; walk; walk = g_list_next (walk)) {
|
||||
|
|
@ -293,6 +295,8 @@ suspend_node (PinosNode *this)
|
|||
g_warning ("error unset format output: %d", res);
|
||||
p->port.buffers = NULL;
|
||||
p->port.n_buffers = 0;
|
||||
if (p->port.allocated)
|
||||
pinos_memblock_free (&p->port.buffer_mem);
|
||||
p->port.allocated = FALSE;
|
||||
}
|
||||
return res;
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
|
||||
|
|
|
|||
|
|
@ -26,8 +26,6 @@ G_BEGIN_DECLS
|
|||
|
||||
typedef struct _PinosMemblock PinosMemblock;
|
||||
|
||||
#include <pinos/server/daemon.h>
|
||||
|
||||
typedef enum {
|
||||
PINOS_MEMBLOCK_FLAG_NONE = 0,
|
||||
PINOS_MEMBLOCK_FLAG_WITH_FD = (1 << 0),
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue