ขนาดวิดีโอ: 1280 X 720853 X 480640 X 360
แสดงแผงควบคุมโปรแกรมเล่น
เล่นอัตโนมัติ
เล่นใหม่
In the function my_free , heap_small[ALLOC_CNT] and heap_large[ALLOC_CNT], both are OOB. It needs to be ALLOC_CNT - 1.
Upon trying this implementation I also found that it is not necessarily the array base address be 32 bytes aligned or 128 bytes. So the mod of address might not necessarily be 0.
Doesn’t the update to the bool array or bitmap need to be atomic?
in free function should the ptr be subtracted from base address of addr and then we should do Modulo ?
yes, that's a bug in the code.
Possible solutionfor (int i = 0; i < ALLOC_CNT; i++) { if (ptr == (void*)heap_small[i]) { used_small[i] = false; break; } if (ptr == (void*)heap_large[i]) { used_large[i] = false; break; } }
your my_free func have critical bug if (addr % HEAP_SMALL == 0) never happen
In the function my_free , heap_small[ALLOC_CNT] and heap_large[ALLOC_CNT], both are OOB. It needs to be ALLOC_CNT - 1.
Upon trying this implementation I also found that it is not necessarily the array base address be 32 bytes aligned or 128 bytes. So the mod of address might not necessarily be 0.
Doesn’t the update to the bool array or bitmap need to be atomic?
in free function should the ptr be subtracted from base address of addr and then we should do Modulo ?
yes, that's a bug in the code.
Possible solution
for (int i = 0; i < ALLOC_CNT; i++) {
if (ptr == (void*)heap_small[i]) {
used_small[i] = false;
break;
}
if (ptr == (void*)heap_large[i]) {
used_large[i] = false;
break;
}
}
your my_free func have critical bug if (addr % HEAP_SMALL == 0) never happen