diff --git a/src/modules/module-protocol-pulse/message.c b/src/modules/module-protocol-pulse/message.c index 19b4f82d6..bbeb7e99e 100644 --- a/src/modules/module-protocol-pulse/message.c +++ b/src/modules/module-protocol-pulse/message.c @@ -383,9 +383,12 @@ static int ensure_size(struct message *m, uint32_t size) if (m->length > m->allocated) return -ENOMEM; - if (m->length + size <= m->allocated) + if (size <= m->allocated - m->length) return size; + if (m->allocated + size < m->allocated) + return -ENOMEM; + alloc = SPA_ROUND_UP_N(SPA_MAX(m->allocated + size, 4096u), 4096u); diff = alloc - m->allocated; if ((data = realloc(m->data, alloc)) == NULL) {