Index: uspace/lib/c/generic/adt/hash_table.c
===================================================================
--- uspace/lib/c/generic/adt/hash_table.c	(revision 1ab4aca491cf0003d347c3cd744f19376766cddd)
+++ uspace/lib/c/generic/adt/hash_table.c	(revision b0f00a9ed1b00bda8a286a4c4bbe625a7f410bc6)
@@ -76,4 +76,24 @@
 	
 	return true;
+}
+
+/** Remove all elements from the hash table
+ *
+ * @param h Hash table to be cleared
+ */
+void hash_table_clear(hash_table_t *h)
+{
+	for (hash_count_t chain = 0; chain < h->entries; ++chain) {
+		link_t *cur;
+		link_t *next;
+		
+		for (cur = h->entry[chain].head.next;
+		    cur != &h->entry[chain].head;
+		    cur = next) {
+			next = cur->next;
+			list_remove(cur);
+			h->op->remove_callback(cur);
+		}
+	}
 }
 
@@ -198,9 +218,17 @@
  */
 void hash_table_apply(hash_table_t *h, void (*f)(link_t *, void *), void *arg)
-{
-	hash_index_t bucket;
-	
-	for (bucket = 0; bucket < h->entries; bucket++) {
-		list_foreach(h->entry[bucket], cur) {
+{	
+	for (hash_index_t bucket = 0; bucket < h->entries; bucket++) {
+		link_t *cur;
+		link_t *next;
+
+		for (cur = h->entry[bucket].head.next; cur != &h->entry[bucket].head;
+		    cur = next) {
+			/*
+			 * The next pointer must be stored prior to the functor
+			 * call to allow using destructor as the functor (the
+			 * free function could overwrite the cur->next pointer).
+			 */
+			next = cur->next;
 			f(cur, arg);
 		}
