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
- 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).
- 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).
- 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.
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