pod: handle pod copy failure

Don't check NULL in pw_spa_pod_copy so that we can check for allocation
failures when the functions returns NULL.
This commit is contained in:
Wim Taymans 2019-01-07 15:36:19 +01:00
parent 7cd55c2c6b
commit de796d34ad
4 changed files with 11 additions and 9 deletions

View file

@ -523,7 +523,7 @@ do_update_port(struct node *this,
port->params = realloc(port->params, port->n_params * sizeof(struct spa_pod *)); port->params = realloc(port->params, port->n_params * sizeof(struct spa_pod *));
for (i = 0; i < port->n_params; i++) { for (i = 0; i < port->n_params; i++) {
port->params[i] = pw_spa_pod_copy(params[i]); port->params[i] = params[i] ? pw_spa_pod_copy(params[i]) : NULL;
if (spa_pod_is_object_id(port->params[i], SPA_PARAM_Format)) if (spa_pod_is_object_id(port->params[i], SPA_PARAM_Format))
port->have_format = true; port->have_format = true;
@ -1028,7 +1028,7 @@ client_node_update(void *data,
this->params = realloc(this->params, this->n_params * sizeof(struct spa_pod *)); this->params = realloc(this->params, this->n_params * sizeof(struct spa_pod *));
for (i = 0; i < this->n_params; i++) for (i = 0; i < this->n_params; i++)
this->params[i] = pw_spa_pod_copy(params[i]); this->params[i] = params[i] ? pw_spa_pod_copy(params[i]) : NULL;
} }
if (change_mask & PW_CLIENT_NODE_UPDATE_PROPS) { if (change_mask & PW_CLIENT_NODE_UPDATE_PROPS) {
pw_node_update_properties(impl->this.node, props); pw_node_update_properties(impl->this.node, props);

View file

@ -423,7 +423,7 @@ struct pw_link_info *pw_link_info_update(struct pw_link_info *info,
} }
if (update->change_mask & PW_LINK_CHANGE_MASK_FORMAT) { if (update->change_mask & PW_LINK_CHANGE_MASK_FORMAT) {
free(info->format); free(info->format);
info->format = pw_spa_pod_copy(update->format); info->format = update->format ? pw_spa_pod_copy(update->format) : NULL;
} }
if (update->change_mask & PW_LINK_CHANGE_MASK_PROPS) { if (update->change_mask & PW_LINK_CHANGE_MASK_PROPS) {
if (info->props) if (info->props)

View file

@ -140,13 +140,18 @@ static struct param *add_param(struct pw_stream *stream,
{ {
struct stream *impl = SPA_CONTAINER_OF(stream, struct stream, this); struct stream *impl = SPA_CONTAINER_OF(stream, struct stream, this);
struct param *p; struct param *p;
struct spa_pod *copy = NULL;
p = pw_array_add(&impl->params, sizeof(struct param)); if (param != NULL && (copy = pw_spa_pod_copy(param)) == NULL)
if (p == NULL)
return NULL; return NULL;
p = pw_array_add(&impl->params, sizeof(struct param));
if (p == NULL) {
free(copy);
return NULL;
}
p->type = type; p->type = type;
p->param = pw_spa_pod_copy(param); p->param = copy;
return p; return p;
} }

View file

@ -59,9 +59,6 @@ pw_spa_pod_copy(const struct spa_pod *pod)
size_t size; size_t size;
struct spa_pod *c; struct spa_pod *c;
if (pod == NULL)
return NULL;
size = SPA_POD_SIZE(pod); size = SPA_POD_SIZE(pod);
if ((c = (struct spa_pod *) malloc(size)) == NULL) if ((c = (struct spa_pod *) malloc(size)) == NULL)
return NULL; return NULL;