pulse-server: don't crash when alloc fails

This commit is contained in:
Wim Taymans 2021-01-28 19:30:32 +01:00
parent 0b69b92dc8
commit 09f423922d

View file

@ -302,22 +302,20 @@ static void message_free(struct impl *impl, struct message *msg, bool dequeue, b
static struct message *message_alloc(struct impl *impl, uint32_t channel, uint32_t size) static struct message *message_alloc(struct impl *impl, uint32_t channel, uint32_t size)
{ {
struct message *msg = NULL; struct message *msg;
if (!spa_list_is_empty(&impl->free_messages)) { if (!spa_list_is_empty(&impl->free_messages)) {
msg = spa_list_first(&impl->free_messages, struct message, link); msg = spa_list_first(&impl->free_messages, struct message, link);
spa_list_remove(&msg->link); spa_list_remove(&msg->link);
pw_log_trace("using recycled message %p", msg); pw_log_trace("using recycled message %p", msg);
} } else {
if (msg == NULL) { if ((msg = calloc(1, sizeof(struct message))) == NULL)
msg = calloc(1, sizeof(struct message)); return NULL;
pw_log_trace("new message %p", msg); pw_log_trace("new message %p", msg);
msg->stat = &impl->stat; msg->stat = &impl->stat;
msg->stat->n_allocated++; msg->stat->n_allocated++;
msg->stat->n_accumulated++; msg->stat->n_accumulated++;
} }
if (msg == NULL)
return NULL;
ensure_size(msg, size); ensure_size(msg, size);
spa_zero(msg->extra); spa_zero(msg->extra);
msg->channel = channel; msg->channel = channel;