linux-prog icon indicating copy to clipboard operation
linux-prog copied to clipboard

Issues with ch7 - malloc implementation

Open ZoranStojsavljevic opened this issue 6 years ago • 0 comments

Hello Andre,

Excellent article, which really prompted me to dive much deeper to Linux implementation than I never intended: https://medium.com/@andrestc/implementing-malloc-and-free-ba7e7704a473

I always naively thought that malloc() is actually a system call, but, in fact, it is only glibc library function, behind scene hiding brk() and sbrk() system calls. As you, Andre, wrote later, it uses mmap() for large chunks of the memory.

Here, I just wanted to point to the part of your article which says: "Beware that this implementation is full of bugs (some are discussed below, some are obvious from reading the real malloc implementation)".

Just wanted to point some of them (I still did not read real malloc() implementation): [1] Why 3 pages (page size = 0x1000), why not 4 (algorithm 2**N, N=2, in this case)? [2] _malloc(0) still assigns 3 pages. Should pass... [3] _malloc(-1) still works. Should not!

These are just initial observations. There are more... I need to try to fix some of these (not only to sob, as old stubborn lady)!

But still... Thank you, Andre! Great Work.

Zoran Stojsavljevic

ZoranStojsavljevic avatar Apr 23 '19 13:04 ZoranStojsavljevic