summaryrefslogtreecommitdiff
path: root/src/modules
diff options
context:
space:
mode:
authorWim Taymans <wtaymans@redhat.com>2019-07-19 13:50:58 +0200
committerWim Taymans <wtaymans@redhat.com>2019-07-19 13:50:58 +0200
commitb23ca2e24d7e806c37dc18d96166d316497b38ff (patch)
treee145ce13147f3c7a8ba4e10fe014454e1dbc37ed /src/modules
parent68208064090f80586aa1c112fd8687a86a5c5e3d (diff)
client-node: track and free activation memory
Diffstat (limited to 'src/modules')
-rw-r--r--src/modules/module-client-node/client-node.c33
-rw-r--r--src/modules/module-client-node/remote-node.c17
2 files changed, 42 insertions, 8 deletions
diff --git a/src/modules/module-client-node/client-node.c b/src/modules/module-client-node/client-node.c
index b6baf020..69626939 100644
--- a/src/modules/module-client-node/client-node.c
+++ b/src/modules/module-client-node/client-node.c
@@ -252,6 +252,17 @@ found:
return m;
}
+
+static inline struct mem *find_mem_fd(struct impl *impl, int fd)
+{
+ struct mem *m;
+ pw_array_for_each(m, &impl->mems) {
+ if (m->fd == fd)
+ return m;
+ }
+ return NULL;
+}
+
static struct mix *find_mix(struct port *p, uint32_t mix_id)
{
struct mix *mix;
@@ -296,10 +307,10 @@ static struct mix *ensure_mix(struct impl *impl, struct port *p, uint32_t mix_id
static void clear_io(struct node *node, struct io *io)
{
struct mem *m;
- spa_log_debug(node->log, "node %p: clear io %p %d %d", node, io, io->id, io->memid);
m = pw_array_get_unchecked(&node->impl->mems, io->memid, struct mem);
m->ref--;
io->id = SPA_ID_INVALID;
+ spa_log_debug(node->log, "node %p: clear io %p %d mem %u %d", node, io, io->id, io->memid, m->ref);
}
static struct io *update_io(struct node *this,
@@ -776,8 +787,7 @@ static int do_port_set_io(struct impl *impl,
return -EINVAL;
mem_offset = SPA_PTRDIFF(data, mem->ptr);
- mem_size = mem->size;
- if (mem_size - mem_offset < size)
+ if (mem_offset + size > mem->size)
return -EINVAL;
mem_offset += mem->offset;
@@ -785,6 +795,7 @@ static int do_port_set_io(struct impl *impl,
if (m == NULL)
return -errno;
memid = m->id;
+ mem_size = size;
}
else {
memid = SPA_ID_INVALID;
@@ -1622,10 +1633,22 @@ static void node_peer_removed(void *data, struct pw_node *peer)
{
struct impl *impl = data;
struct node *this = &impl->node;
+ struct mem *m;
if (this->resource == NULL)
return;
+ m = find_mem_fd(impl, peer->activation->fd);
+ if (m == NULL) {
+ pw_log_warn(NAME " %p: unknown peer %p fd:%d", &impl->this, peer,
+ peer->source.fd);
+ return;
+ }
+ m->ref--;
+
+ pw_log_debug(NAME " %p: peer %p %u removed", &impl->this, peer,
+ peer->info.id);
+
pw_client_node_resource_set_activation(this->resource,
peer->info.id,
-1,
@@ -1636,6 +1659,10 @@ static void node_peer_removed(void *data, struct pw_node *peer)
static void node_driver_changed(void *data, struct pw_node *old, struct pw_node *driver)
{
+ struct impl *impl = data;
+
+ pw_log_debug(NAME " %p: driver changed %p -> %p", &impl->this, old, driver);
+
node_peer_removed(data, old);
node_peer_added(data, driver);
}
diff --git a/src/modules/module-client-node/remote-node.c b/src/modules/module-client-node/remote-node.c
index c4a2e3c0..25869d07 100644
--- a/src/modules/module-client-node/remote-node.c
+++ b/src/modules/module-client-node/remote-node.c
@@ -141,7 +141,7 @@ static struct mem *find_mem_ptr(struct node_data *data, void *ptr)
{
struct mem *m;
pw_array_for_each(m, &data->mems) {
- if (m->map.ptr == ptr)
+ if (ptr >= m->map.ptr && ptr < SPA_MEMBER(m->map.ptr, m->map.map.size, void))
return m;
}
return NULL;
@@ -208,8 +208,13 @@ static void clear_mem(struct node_data *data, struct mem *m)
static void clear_link(struct node_data *data, struct link *link)
{
+ struct mem *m;
+
link->node_id = SPA_ID_INVALID;
link->target.activation = NULL;
+ m = find_mem(data, link->mem_id);
+ if (m && --m->ref == 0)
+ clear_mem(data, m);
close(link->signalfd);
spa_list_remove(&link->target.link);
}
@@ -873,8 +878,8 @@ client_node_port_set_io(void *object,
m->ref++;
}
- pw_log_debug("port %p: set io %s %p", mix->port,
- spa_debug_type_find_name(spa_type_io, id), ptr);
+ pw_log_debug("port %p: set io %s %p %p", mix->port,
+ spa_debug_type_find_name(spa_type_io, id), ptr, mix->mix.io);
if (id == SPA_IO_Buffers) {
if (ptr == NULL && mix->mix.io) {
@@ -954,7 +959,7 @@ client_node_set_activation(void *object,
}
m->ref++;
}
- pw_log_debug("node %p: set activation %d", node, node_id);
+ pw_log_debug("node %p: set activation %d %p %u %u", node, node_id, ptr, offset, size);
if (data->remote_id == node_id) {
pw_log_debug("node %p: our activation %u: %u %u %u %p", node, node_id,
@@ -978,7 +983,9 @@ client_node_set_activation(void *object,
link->target.node = NULL;
spa_list_append(&node->rt.target_list, &link->target.link);
- pw_log_debug("node %p: state %p required %d, pending %d", node,
+ pw_log_debug("node %p: link %p: fd:%d id:%u state %p required %d, pending %d",
+ node, link, signalfd,
+ link->target.activation->position.clock.id,
&link->target.activation->state[0],
link->target.activation->state[0].required,
link->target.activation->state[0].pending);