Confusing line in free overview
k4lizen opened this issue · comments
So here, we have some interesting things. Basically, if the size of the chunk being freed is larger than FASTBIN_CONSOLIDATION_THRESHOLD (0x10000), we trigger something called fastbin consolidation with the malloc_consolidate function. After that, if the size of the chunk get's beyond a certain threshold, it will call the systrim function. This will effectively trim off a piece of memory from the top chunk, and give it back to the system. If that isn't the case, it will try to use the heap_trim function, which if conditions are right might delete a heap.
The way the sentence is worded, it implies that if FASTBIN_CONSOLIDATION_THRESHOLD
isn't met, heap_trim
will be used. However, as seen in the code provided, FASTBIN_CONSOLIDATION_THRESHOLD
needs to be met, and the chunk must not be in the main arena for the heap_trim
function to be tried. Code can also be seen here: https://elixir.bootlin.com/glibc/glibc-2.39/source/malloc/malloc.c#L4788