From fc6f8e3448a45927896f666aa17485729ce8e0c4 Mon Sep 17 00:00:00 2001 From: Pauli Virtanen Date: Sat, 3 Feb 2024 13:15:31 +0200 Subject: [PATCH] client-node: clear buffers always when freeing mix Avoid leaking buffers when freeing mix, in case the port was not cleared properly. These leaks don't seem to be occurring currently, but better be sure. --- src/modules/module-client-node/client-node.c | 33 +++++++++++++------- 1 file changed, 21 insertions(+), 12 deletions(-) diff --git a/src/modules/module-client-node/client-node.c b/src/modules/module-client-node/client-node.c index ab019d36e..4edd43096 100644 --- a/src/modules/module-client-node/client-node.c +++ b/src/modules/module-client-node/client-node.c @@ -238,18 +238,6 @@ fail: return NULL; } -static void free_mix(struct port *p, struct mix *mix) -{ - if (mix == NULL) - return; - - /* never realloc so it's safe to call from pw_map_foreach */ - if (mix->mix_id < pw_map_get_size(&p->mix)) - pw_map_insert_at(&p->mix, mix->mix_id, NULL); - - free(mix); -} - static void clear_data(struct impl *impl, struct spa_data *d) { switch (d->type) { @@ -297,6 +285,27 @@ static int clear_buffers(struct impl *impl, struct mix *mix) return 0; } +static void free_mix(struct port *p, struct mix *mix) +{ + struct impl *impl = p->impl; + + if (mix == NULL) + return; + + if (mix->n_buffers) { + /* this shouldn't happen */ + spa_log_warn(impl->log, "%p: mix port-id:%u freeing leaked buffers", impl, mix->mix_id - 1u); + } + + clear_buffers(impl, mix); + + /* never realloc so it's safe to call from pw_map_foreach */ + if (mix->mix_id < pw_map_get_size(&p->mix)) + pw_map_insert_at(&p->mix, mix->mix_id, NULL); + + free(mix); +} + static void mix_clear(struct impl *impl, struct mix *mix) { struct port *port = mix->port;