StrayexOS
StrayexOS copied to clipboard
Possible bug in kfree()
When kfree is called, it uses sizeof()
to get the size of the pointer. However, if I'm remembering correctly, this will return the size of the pointer, not the size of the memory region. I would recommend adding a header above each region of memory to keep track of region sizes and the like. An example header could be:
typedef struct
{
uint32_t size;
int magic;
} mem_header_t;
You could then allocate a region of the requested size plus the size of the header, and insert one above the region allocated. The pointer returned would point to the memory beneath the header, so just subtract the size of the header from the pointer to get the header's address.
Hello @hello01-debug
Yes, I'm aware of this problem. When I wrote the memory management function I didn't know how to solve the problem of controlling single areas of memory. Now I know more about memory and your idea is great. I'm currently working over another my project, but when I will write some code here again, I will get the solution done.