mirror of
https://gitlab.freedesktop.org/pipewire/pipewire.git
synced 2025-11-04 13:30:12 -05:00
pipewire: improve memory cleanup
Add method to unload a spa interface. Various other memory cleanups
This commit is contained in:
parent
0dc036ac84
commit
d165b3b842
8 changed files with 362 additions and 80 deletions
|
|
@ -1084,6 +1084,10 @@ static int node_clear(struct node *this)
|
|||
{
|
||||
uint32_t i;
|
||||
|
||||
for (i = 0; i < this->n_params; i++)
|
||||
free(this->params[i]);
|
||||
free(this->params);
|
||||
|
||||
for (i = 0; i < MAX_INPUTS; i++) {
|
||||
if (this->in_ports[i].valid)
|
||||
clear_port(this, &this->in_ports[i], SPA_DIRECTION_INPUT, i);
|
||||
|
|
@ -1186,6 +1190,8 @@ static void node_free(void *data)
|
|||
if (impl->io_areas)
|
||||
pw_memblock_free(impl->io_areas);
|
||||
|
||||
pw_map_clear(&impl->io_map);
|
||||
|
||||
if (impl->fds[0] != -1)
|
||||
close(impl->fds[0]);
|
||||
if (impl->fds[1] != -1)
|
||||
|
|
|
|||
|
|
@ -442,14 +442,20 @@ static int negotiate_buffers(struct impl *impl)
|
|||
spa_buffer_alloc_fill_info(&info, 0, NULL, blocks, datas, aligns);
|
||||
info.skel_size = SPA_ROUND_UP_N(info.skel_size, 16);
|
||||
|
||||
if (impl->buffers)
|
||||
free(impl->buffers);
|
||||
impl->buffers = calloc(blocks, sizeof(struct spa_buffer *) + info.skel_size);
|
||||
if (impl->buffers == NULL)
|
||||
return -ENOMEM;
|
||||
|
||||
|
||||
skel = SPA_MEMBER(impl->buffers, sizeof(struct spa_buffer *) * blocks, void);
|
||||
data_size = info.meta_size + info.chunk_size + info.data_size;
|
||||
|
||||
if (impl->mem) {
|
||||
pw_memblock_free(impl->mem);
|
||||
impl->mem = NULL;
|
||||
}
|
||||
|
||||
if ((res = pw_memblock_alloc(PW_MEMBLOCK_FLAG_WITH_FD |
|
||||
PW_MEMBLOCK_FLAG_MAP_READWRITE |
|
||||
PW_MEMBLOCK_FLAG_SEAL, blocks * data_size,
|
||||
|
|
@ -800,18 +806,32 @@ static void client_node_initialized(void *data)
|
|||
pw_node_set_active(impl->this.node, true);
|
||||
}
|
||||
|
||||
static void cleanup(struct impl *impl)
|
||||
{
|
||||
if (impl->use_converter) {
|
||||
if (impl->adapter)
|
||||
pw_unload_spa_interface(impl->adapter);
|
||||
}
|
||||
|
||||
if (impl->buffers)
|
||||
free(impl->buffers);
|
||||
if (impl->mem) {
|
||||
pw_memblock_free(impl->mem);
|
||||
impl->mem = NULL;
|
||||
}
|
||||
free(impl);
|
||||
}
|
||||
|
||||
static void client_node_destroy(void *data)
|
||||
{
|
||||
struct impl *impl = data;
|
||||
|
||||
pw_log_debug("client-stream %p: destroy", &impl->this);
|
||||
|
||||
spa_hook_remove(&impl->client_node_listener);
|
||||
|
||||
spa_hook_remove(&impl->node_listener);
|
||||
pw_node_destroy(impl->this.node);
|
||||
|
||||
free(impl);
|
||||
cleanup(impl);
|
||||
}
|
||||
|
||||
static void client_node_async_complete(void *data, uint32_t seq, int res)
|
||||
|
|
@ -847,8 +867,7 @@ static void node_destroy(void *data)
|
|||
|
||||
spa_hook_remove(&impl->client_node_listener);
|
||||
pw_client_node_destroy(impl->client_node);
|
||||
|
||||
free(impl);
|
||||
cleanup(impl);
|
||||
}
|
||||
|
||||
static const struct pw_node_events node_events = {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue