fixed allocator use after free and added some somments

This commit is contained in:
cozis
2022-04-19 01:30:32 +02:00
parent 7a77020c29
commit 8e3b4411ed
+10 -3
View File
@@ -53,9 +53,11 @@ xj_alloc *xj_alloc_using(void *mem, int size, int ext, void (*free)(void*))
void xj_alloc_del(xj_alloc *alloc) void xj_alloc_del(xj_alloc *alloc)
{ {
if(alloc->free != NULL) // Free all of the allocator's chunks,
alloc->free(alloc); // with exception of the first one,
// which is allocated with the allocator's
// header and must be deallocated with
// the user-provided callback-
chunk_t *curr = alloc->tail; chunk_t *curr = alloc->tail;
while(curr->prev != NULL) while(curr->prev != NULL)
{ {
@@ -63,6 +65,11 @@ void xj_alloc_del(xj_alloc *alloc)
free(curr); free(curr);
curr = prev; curr = prev;
} }
// Free the allocator header and first
// chunk.
if(alloc->free != NULL)
alloc->free(alloc);
} }
unsigned long long next_aligned(unsigned long long n) unsigned long long next_aligned(unsigned long long n)