Skip to content

Bug: allocator may leak or fragment memory #2

@io-eric

Description

@io-eric

What: The simple free-list allocator in include/webcc/core/allocator.h can cause fragmentation and may not coalesce adjacent free blocks; edge-cases (e.g., malloc(0)) need clarification and tests.

Where: include/webcc/core/allocator.h

Repro: Write tests that allocate and free various sized blocks repeatedly and observe whether freed memory is reused or memory growth increases unnecessarily.

Proposed fix:

  • Implement block coalescing in free() to merge adjacent free blocks.
  • Add unit tests that exercise alloc/free reuse and fragmentation scenarios.
  • Document behavior for malloc(0) in the header/docs.

Acceptance criteria:

  • Unit tests show freed blocks are reused and fragmentation is reduced.
  • Memory growth in repeated alloc/free tests is improved.
  • Header or docs include a clear statement about malloc(0) behavior.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't workingtestsAdd or fix tests

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions