Skip to content

Commit

Permalink
Ensure remaining size is stored correctly in the arena allocator
Browse files Browse the repository at this point in the history
  • Loading branch information
lpereira committed Aug 19, 2024
1 parent 4b47775 commit 99e23b7
Showing 1 changed file with 4 additions and 3 deletions.
7 changes: 4 additions & 3 deletions src/lib/lwan-arena.c
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ void arena_destroy(struct arena *a)
arena_init(a);
}

static void *arena_bump_ptr(struct arena *a, size_t sz)
static inline void *arena_bump_ptr(struct arena *a, size_t sz)
{
void *ptr = a->bump_ptr_alloc.ptr;

Expand All @@ -56,7 +56,8 @@ void *arena_alloc(struct arena *a, size_t sz)
sz = (sz + sizeof(void *) - 1ul) & ~(sizeof(void *) - 1ul);

if (a->bump_ptr_alloc.remaining < sz) {
void *ptr = malloc(LWAN_MAX((size_t)PAGE_SIZE, sz));
size_t alloc_sz = LWAN_MAX((size_t)PAGE_SIZE, sz);
void *ptr = malloc(alloc_sz);

if (UNLIKELY(!ptr))
return NULL;
Expand All @@ -70,7 +71,7 @@ void *arena_alloc(struct arena *a, size_t sz)
*saved_ptr = ptr;

a->bump_ptr_alloc.ptr = ptr;
a->bump_ptr_alloc.remaining = PAGE_SIZE;
a->bump_ptr_alloc.remaining = alloc_sz;
}

return arena_bump_ptr(a, sz);
Expand Down

0 comments on commit 99e23b7

Please sign in to comment.