mirror of
https://gitlab.freedesktop.org/pipewire/pipewire.git
synced 2025-11-03 09:01:54 -05:00
handle realloc error better
Make sure we free the old pointer, clear it and set the array size to 0. Use reallocarray where possible.
This commit is contained in:
parent
9e3b784b34
commit
ba7d410c3c
10 changed files with 240 additions and 120 deletions
|
|
@ -317,8 +317,15 @@ static int add_node_update(struct node_data *data, uint32_t change_mask, uint32_
|
|||
res = spa_node_enum_params_sync(node->node,
|
||||
id, &idx, NULL, ¶m, &b.b);
|
||||
if (res == 1) {
|
||||
params = realloc(params, sizeof(struct spa_pod *) * (n_params + 1));
|
||||
params[n_params++] = spa_pod_copy(param);
|
||||
void *p;
|
||||
p = reallocarray(params, n_params + 1, sizeof(struct spa_pod *));
|
||||
if (p == NULL) {
|
||||
res = -errno;
|
||||
pw_log_error("realloc failed: %m");
|
||||
} else {
|
||||
params = p;
|
||||
params[n_params++] = spa_pod_copy(param);
|
||||
}
|
||||
}
|
||||
spa_pod_dynamic_builder_clean(&b);
|
||||
if (res != 1)
|
||||
|
|
@ -376,8 +383,15 @@ static int add_port_update(struct node_data *data, struct pw_impl_port *port, ui
|
|||
port->direction, port->port_id,
|
||||
id, &idx, NULL, ¶m, &b.b);
|
||||
if (res == 1) {
|
||||
params = realloc(params, sizeof(struct spa_pod *) * (n_params + 1));
|
||||
params[n_params++] = spa_pod_copy(param);
|
||||
void *p;
|
||||
p = reallocarray(params, n_params + 1, sizeof(struct spa_pod*));
|
||||
if (p == NULL) {
|
||||
res = -errno;
|
||||
pw_log_error("realloc failed: %m");
|
||||
} else {
|
||||
params = p;
|
||||
params[n_params++] = spa_pod_copy(param);
|
||||
}
|
||||
}
|
||||
spa_pod_dynamic_builder_clean(&b);
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue