Allocator Pairing: The `aligned_alloc` vs. `malloc` Deallocation Trap

A critical pitfall arises from mismatched allocation and deallocation functions; for instance, C11's `aligned_alloc` requires `free()` for deallocation, while Microsoft Visual C++'s `_aligned_malloc` needs `_aligned_free()`. Using the wrong deallocation function for aligned memory can lead to undefined behavior, memory leaks, or crashes due to the allocator's internal bookkeeping mechanisms.

Sources

Open the full topic