client-node: handle port_buffers errors better

First check if all of the new buffers are ok before attemping to replace
our exising ones with the new ones. Else we might end up copying some
of the new buffers and cleaning them up twice later.
This commit is contained in:
Wim Taymans 2023-11-20 09:36:02 +01:00
parent 7cd242bffb
commit 0ae797ea28

View file

@ -1052,6 +1052,11 @@ static int client_node_port_buffers(void *data,
if (mix->n_buffers != n_buffers)
goto invalid;
for (i = 0; i < n_buffers; i++) {
if (mix->buffers[i].outbuf->n_datas != buffers[i]->n_datas)
goto invalid;
}
for (i = 0; i < n_buffers; i++) {
struct spa_buffer *oldbuf, *newbuf;
struct buffer *b = &mix->buffers[i];
@ -1061,9 +1066,6 @@ static int client_node_port_buffers(void *data,
spa_log_debug(impl->log, "buffer %d n_datas:%d", i, newbuf->n_datas);
if (oldbuf->n_datas != newbuf->n_datas)
goto invalid;
for (j = 0; j < b->buffer.n_datas; j++) {
struct spa_chunk *oldchunk = oldbuf->datas[j].chunk;
struct spa_data *d = &newbuf->datas[j];
@ -1080,8 +1082,6 @@ static int client_node_port_buffers(void *data,
d->maxsize);
}
}
mix->n_buffers = n_buffers;
return 0;
invalid:
for (i = 0; i < n_buffers; i++)