add: galloc: free: check if the ptr is valid

This commit is contained in:
2023-07-23 19:38:40 +02:00
parent c688cfc4b1
commit 1d9de5df65
2 changed files with 9 additions and 2 deletions

View File

@ -144,6 +144,11 @@ free(ptr)
local first_block;
local last_block;
if (ptr > heap + HEAP_SIZE | heap > ptr)
{
putstr("Error: free: invalid ptr\n");
return;
}
block = ptr - LOCATION_DATA;
prev_block = [block + LOCATION_PREV];
if (prev_block == 0 | [prev_block + LOCATION_USED])
@ -160,5 +165,5 @@ free(ptr)
leaks()
{
return (heap + LOCATION_NEXT != NULL);
return ([heap + LOCATION_NEXT] != 0);
}