Skip to content

tlsf_realloc does not preserve the original alignment requirement of memory allocated by tlsf_memalign #36

Description

@Guozhanxin

I encountered a potential issue when using the TLSF memory allocator: memory allocated via tlsf_memalign with a specific alignment requirement may lose this alignment after being reallocated via tlsf_realloc.

Reproduction Scenario

  1. Allocate memory using tlsf_memalign(align, size), where align is a custom alignment value higher than the system's default alignment (ALIGN_SIZE) (e.g., 128 bytes).
  2. Call tlsf_realloc to expand the memory block, and the expansion cannot be satisfied by merging adjacent free blocks in-place (triggering the reallocation logic).
  3. At this point, tlsf_realloc internally calls tlsf_malloc to allocate new memory. However, tlsf_malloc only guarantees the system's default alignment and does not inherit the original alignment requirement from tlsf_memalign, resulting in the new address failing to meet the expected alignment.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions