From 112fbe00a4e7fe23b7314485304df7a9b029fda6 Mon Sep 17 00:00:00 2001
From: Lukas Fleischer <calcurse@cryptocrack.de>
Date: Mon, 18 Apr 2011 01:18:03 +0200
Subject: 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>
---
 src/llist.c | 7 ++++++-
 1 file changed, 6 insertions(+), 1 deletion(-)

(limited to 'src')

diff --git a/src/llist.c b/src/llist.c
index 021de82..e24f9fc 100644
--- a/src/llist.c
+++ b/src/llist.c
@@ -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);
+        {
+          fn_free(i->data);
+          i->data = NULL;
+        }
     }
 }
 
-- 
cgit v1.2.3-70-g09d2