From d27b135b3aa15b45988cf292b1e146fbf02350cf Mon Sep 17 00:00:00 2001 From: Caio Oliveira Date: Mon, 25 Sep 2023 14:46:49 -0700 Subject: [PATCH] util: Fix bookkeeping of linear node sizes MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit When creating a new node, we were clobbering the original size requested, and use that as offset, so the node would always be full. Fixes: 591db9a9a54 ("util: Remove per-buffer header in linear alloc for release mode") Reviewed-by: Marek Olšák Part-of: --- src/util/ralloc.c | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/src/util/ralloc.c b/src/util/ralloc.c index b74bae25b4d..b760ddb0a68 100644 --- a/src/util/ralloc.c +++ b/src/util/ralloc.c @@ -1010,11 +1010,12 @@ linear_alloc_child(linear_ctx *ctx, unsigned size) if (unlikely(ctx->offset + size > ctx->size)) { /* allocate a new node */ - if (likely(size < MIN_LINEAR_BUFSIZE)) - size = MIN_LINEAR_BUFSIZE; + unsigned node_size = size; + if (likely(node_size < MIN_LINEAR_BUFSIZE)) + node_size = MIN_LINEAR_BUFSIZE; const unsigned canary_size = get_node_canary_size(); - const unsigned full_size = canary_size + size; + const unsigned full_size = canary_size + node_size; /* linear context is also a ralloc context */ char *ptr = ralloc_size(ctx, full_size); @@ -1022,7 +1023,7 @@ linear_alloc_child(linear_ctx *ctx, unsigned size) return NULL; ctx->offset = 0; - ctx->size = size; + ctx->size = node_size; ctx->latest = ptr + canary_size; #ifndef NDEBUG linear_node_canary *canary = get_node_canary(ctx->latest);