LLD icon indicating copy to clipboard operation
LLD copied to clipboard

fix malloc mmap implementation's header size

Open chm46e opened this issue 1 year ago • 1 comments

Hey!

I am working on a similar project and am taking some guidance. I was looking through your malloc implementation and found a logical error. In the mmap call, you seem to have mixed up HEADER_SIZE_MASK and HEADER_SIZE This probably hasn't been tested. (as allocations over 128kb are rare)

old header size: 4294967288 bytes new header size: 4 bytes diff: -4294967284 bytes (:D)

chm46e avatar Mar 02 '23 21:03 chm46e

Let me be clear, I'm a newcomer to memory management.

I found another logical error: In the comment, you explain, that mmap chunk consists of only start header and data. But in the next calls to set size and flags for the mmap chunk, it writes to both start header and end header. The End header doesn't exist? (isn't allocated for & doesn't comply with comment).

So my proposals are:

  1. change mmap chunk's implementation to allocate for the end header
  2. check for FLAG_MEM_MAPPED in all header modifier functions

chm46e avatar Mar 02 '23 21:03 chm46e