Memory Allocation
Files used -> 11-memory-alloc.c, 11-memory-alloc.exe
Last updated
Files used -> 11-memory-alloc.c, 11-memory-alloc.exe
Last updated
In terms of memory so far we saw how static memory management happens using stack.
Now we will have a look on dynamic memory management using heap.
Here in the first highlighted part, we have our prologue and some c lib function probably printf/scanf as we can see offset being pushed.
In the next highlighted part we have another function call.
Lets look into it
Another function call here, looking into it→
Here, we can see inside the highlighted area that we have a call to ‘HeapAlloc’.
Now with this simple info, we can get an idea that this function inside which we got into from main, is allocating memory in heap, and the function which is used for this is ‘malloc’. And that means our function sub_409251 can possibly be malloc function.
Now back to main function and proceeding from there.
In this, starting from the top.
Function renamed to possible_malloc
4 function calls possibly scanf, printf. And can be ignored.
Lastly, a function call which does not seems to be scanf/printf. (Highlighted in orange)
Lets look into this function.
We see a parameter- lpMem. Which gives us hint that it might be memory related function.
On going inside that function we can see →
Call to HeapFree function. Which means the function we dived in is basically deallocating the memory. And in heap, its done via free() function.
Lets look at the source code→
And we can see, malloc and free function being used.