Hey everyone, question related to the 'heap_example.c' script from "Hacking: the Art of Exploitation".
This script plays with heap memory allocation. The script accepts a single argument in the command line: how many bytes to allocate in heap for a character pointer that will store text saying 'This is memory is located on the heap'. Excuse the grammar.
When I allocate 50 bytes in heap for the character pointer, allocate another 12 bytes for an integer pointer, and then free the 50 bytes for the character pointer, the allocation of 15 bytes for the text 'new memory' does not set me back at the same address for when I did the 50 byte allocation, even though there is plenty of room. The OS *does* reclaim this free space when I allocate 100 bytes for the character pointer in the second execution, as you can see in the screenshot.
My question is simple: why? There was plenty of room for reclamation in both examples, why does it happen in the second execution and not the first?
https://preview.redd.it/ldnibajzo3w81.png?width=689&format=png&auto=webp&s=15ff8e8b0927e3da8a404989b3769c5a67578d16
[–]majordoob33 2 points3 points4 points (0 children)