llist.c: Nullify pointers after free()'ing.
* Set all data members to "NULL" in llist_free_inner() after freeing them. Altough we normally shouldn't continue working with a list that already went through llist_free_inner(), this will protect against dangling pointer bugs in case anyone will ever come up with the idea of doing so. * Set list head to "NULL" in llist_free(), basically to put the list into an initialized state. Signed-off-by: Lukas Fleischer <calcurse@cryptocrack.de>
This commit is contained in:
parent
fb5f9d0155
commit
112fbe00a4
@ -52,6 +52,8 @@ llist_free (llist_t *l)
|
||||
t = i->next;
|
||||
mem_free (i);
|
||||
}
|
||||
|
||||
l->head = NULL;
|
||||
}
|
||||
|
||||
void
|
||||
@ -62,7 +64,10 @@ llist_free_inner (llist_t *l, llist_fn_free_t fn_free)
|
||||
for (i = l->head; i; i = i->next)
|
||||
{
|
||||
if (i->data)
|
||||
{
|
||||
fn_free(i->data);
|
||||
i->data = NULL;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user