Don't leak memory

This commit is contained in:
Juhani Krekelä 2018-08-11 19:45:41 +03:00
parent 1ff08c0189
commit 7345815424

View file

@ -56,11 +56,13 @@ struct __free_list {
)
#define TRY_MALLOC(size) TRY_MEMALLOC(malloc, size)
static void __remove_free_list(struct __free_list **head, void *ptr) {
static void __remove_free_list(struct __free_list **head, void *ptr, void(*free)(void*)) {
struct __free_list **current = head;
while (*current != NULL) {
if (current[0]->ptr == ptr) {
struct __free_list *deleted = *current;
*current = current[0]->next;
free(deleted);
break;
}
current = &current[0]->next;
@ -68,7 +70,7 @@ static void __remove_free_list(struct __free_list **head, void *ptr) {
}
#define TRY_FREE(allocation) (\
free(allocation),\
__remove_free_list(&__allocations, allocation)\
__remove_free_list(&__allocations, allocation, free)\
)
#define TRY_FREE_ALL() \
while (__allocations != NULL) {\