aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorErik Liodden <eriklio@stud.ntnu.no>2018-01-03 00:33:13 +0100
committerErik Liodden <eriklio@stud.ntnu.no>2018-01-03 00:33:13 +0100
commit0af0ccdea375ebdb786d6001c94ab75ed194aa7f (patch)
tree79c589180cb861689b122347972004719ed185e8
parentdd3612925823116cfc306c894ba51adcc66e3336 (diff)
downloadalgdat-0af0ccdea375ebdb786d6001c94ab75ed194aa7f.tar.gz
llist: clean up memory
i am still not sure if remove_node should delete the node as well or if it should only remove it from the list. i will not delete it for the moment.
-rw-r--r--llist.c18
1 files changed, 10 insertions, 8 deletions
diff --git a/llist.c b/llist.c
index 6c98d1d..b7c18ce 100644
--- a/llist.c
+++ b/llist.c
@@ -65,11 +65,19 @@ void llist_insert_beginning(struct llist *l, struct llist_node *node)
llist_insert_after(l->nil, node);
}
+void llist_destroy_node(struct llist_node *node)
+{
+ if (node->freefn)
+ node->freefn(node->elem);
+ free(node->elem);
+ free(node);
+}
+
void llist_remove_node(struct llist_node *node)
{
node->prev->next = node->next;
node->next->prev = node->prev;
- /* TODO: destroy node */
+ /* llist_destroy_node(node); */
}
void llist_get_elem(struct llist_node *node, void *elem_addr)
@@ -77,17 +85,11 @@ void llist_get_elem(struct llist_node *node, void *elem_addr)
memcpy(elem_addr, node->elem, node->elem_size);
}
-void llist_destroy_node(struct llist_node *node)
-{
- if (node->freefn)
- node->freefn(node->elem);
- free(node);
-}
-
void llist_dispose(struct llist *l)
{
struct llist_node *node = l->nil->next;
while ((node = node->next) != l->nil)
llist_destroy_node(node->prev);
+ free(l->nil->elem);
free(l->nil);
}