From 09f423922d8fca454d1e564ad9eb8b8f32a8056d Mon Sep 17 00:00:00 2001 From: Wim Taymans Date: Thu, 28 Jan 2021 19:30:32 +0100 Subject: [PATCH] pulse-server: don't crash when alloc fails --- src/modules/module-protocol-pulse/pulse-server.c | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/src/modules/module-protocol-pulse/pulse-server.c b/src/modules/module-protocol-pulse/pulse-server.c index 4eb576989..41160e9b2 100644 --- a/src/modules/module-protocol-pulse/pulse-server.c +++ b/src/modules/module-protocol-pulse/pulse-server.c @@ -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) { - struct message *msg = NULL; + struct message *msg; if (!spa_list_is_empty(&impl->free_messages)) { msg = spa_list_first(&impl->free_messages, struct message, link); spa_list_remove(&msg->link); pw_log_trace("using recycled message %p", msg); - } - if (msg == NULL) { - msg = calloc(1, sizeof(struct message)); + } else { + if ((msg = calloc(1, sizeof(struct message))) == NULL) + return NULL; pw_log_trace("new message %p", msg); msg->stat = &impl->stat; msg->stat->n_allocated++; msg->stat->n_accumulated++; } - if (msg == NULL) - return NULL; ensure_size(msg, size); spa_zero(msg->extra); msg->channel = channel;