42-malloc icon indicating copy to clipboard operation
42-malloc copied to clipboard

empty block in the chained list

Open FXC-ai opened this issue 6 months ago • 1 comments

I’ve been reviewing your code and noticed something: your implementation can create empty blocks. The divide_block function splits an available block into two parts — one for the user (with enough space for their data) and one new free block. However, if the remaining space is exactly 32 bytes, it will only be large enough to hold the block’s metadata, leaving no room for user data. In other words, this creates a “dead” block that wastes space in the heap.

Here is the test which prove it :

TINY : 0x7D0CBF435000 0x7D0CBF435050 - 0x7D0CBF435080 : 48 octets 0x7D0CBF4350A0 - 0x7D0CBF4350E0 : 64 octets Total : 112 octets TINY : 0x7D0CBF435000 0x7D0CBF4350A0 - 0x7D0CBF4350E0 : 64 octets Total : 64 octets TINY : 0x7D0CBF435000 0x7D0CBF435050 - 0x7D0CBF435060 : 16 octets 0x7D0CBF4350A0 - 0x7D0CBF4350E0 : 64 octets Total : 80 octets

7D0CBF4350A0 - 7D0CBF435060 = 32 bytes = 2 * sizeof(t_block)

Did you notice this behavior when implementing the allocator and decide to ignore it, or was it unintentional?

FXC-ai avatar Oct 20 '25 17:10 FXC-ai