From a9911f68a0758c36bcd4ff0badeb440237b3b055 Mon Sep 17 00:00:00 2001 From: Pauli Virtanen Date: Fri, 29 Mar 2024 19:51:07 +0200 Subject: [PATCH] client-node: free port io memmap also if port gone clear_port() clears all struct mix and removes the port, and can occur before port io is set to NULL. In this case the port memmaps are not freed, and are leaked until client pool closes. Fix by freeing the old io memmap when setting io to NULL, also when the port was already cleared, so that the memmap lifecycle is the same as that of the IO. --- src/modules/module-client-node/client-node.c | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) diff --git a/src/modules/module-client-node/client-node.c b/src/modules/module-client-node/client-node.c index 4edd43096..a730c8808 100644 --- a/src/modules/module-client-node/client-node.c +++ b/src/modules/module-client-node/client-node.c @@ -692,15 +692,19 @@ static int do_port_set_io(struct impl *impl, direction == SPA_DIRECTION_INPUT ? "input" : "output", port_id, mix_id, data, size); - port = GET_PORT(impl, direction, port_id); - if (port == NULL) - return data == NULL ? 0 : -EINVAL; - - if ((mix = find_mix(port, mix_id)) == NULL) - return -EINVAL; - old = pw_mempool_find_tag(impl->client_pool, tag, sizeof(tag)); + port = GET_PORT(impl, direction, port_id); + if (port == NULL) { + pw_memmap_free(old); + return data == NULL ? 0 : -EINVAL; + } + + if ((mix = find_mix(port, mix_id)) == NULL) { + pw_memmap_free(old); + return -EINVAL; + } + if (data) { mm = pw_mempool_import_map(impl->client_pool, impl->context_pool, data, size, tag);