From 05deba85a4dbdac1d07cbeea3ead2183daab4a3c Mon Sep 17 00:00:00 2001 From: Wim Taymans Date: Wed, 18 May 2022 17:26:58 +0200 Subject: [PATCH] pulse-server: reset message length when freeing When we move a message to the free list, reset the length to 0. Otherwise the previous length plus the new length will be used to allocated the message size, which would overallocate. --- src/modules/module-protocol-pulse/message.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/src/modules/module-protocol-pulse/message.c b/src/modules/module-protocol-pulse/message.c index 641b4ef6b..43b7ba2a3 100644 --- a/src/modules/module-protocol-pulse/message.c +++ b/src/modules/module-protocol-pulse/message.c @@ -825,12 +825,12 @@ struct message *message_alloc(struct impl *impl, uint32_t channel, uint32_t size 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); + pw_log_trace("using recycled message %p size:%d", msg, size); } else { if ((msg = calloc(1, sizeof(*msg))) == NULL) return NULL; - pw_log_trace("new message %p", msg); + pw_log_trace("new message %p size:%d", msg, size); msg->stat = &impl->stat; msg->stat->n_allocated++; msg->stat->n_accumulated++; @@ -864,7 +864,8 @@ void message_free(struct impl *impl, struct message *msg, bool dequeue, bool des free(msg->data); free(msg); } else { - pw_log_trace("recycle message %p size:%d", msg, msg->allocated); + pw_log_trace("recycle message %p size:%d/%d", msg, msg->length, msg->allocated); spa_list_append(&impl->free_messages, &msg->link); + msg->length = 0; } }