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.
This commit is contained in:
Pauli Virtanen 2024-02-03 13:15:31 +02:00
parent 1196429c09
commit c387506f63

View file

@ -238,18 +238,6 @@ fail:
return NULL; 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) static void clear_data(struct impl *impl, struct spa_data *d)
{ {
switch (d->type) { switch (d->type) {
@ -297,6 +285,27 @@ static int clear_buffers(struct impl *impl, struct mix *mix)
return 0; 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) static void mix_clear(struct impl *impl, struct mix *mix)
{ {
struct port *port = mix->port; struct port *port = mix->port;