Index: test/Makefile
===================================================================
--- test/Makefile	(revision 227)
+++ test/Makefile	(revision 228)
@@ -5,5 +5,5 @@
 OPTS=-std=gnu99 -pedantic -Wall -ggdb
 INC:=-I../trunk/include -I../trunk/src -I/usr/local/include 
-LIB=-L/usr/local/lib -lm -lpthread
+LIB=-L/usr/local/lib -lm -lpthread -ltalloc
 
 REGFI_THREADTEST=regfi-threadtest
@@ -14,6 +14,5 @@
 
 deps:
-	cd ../trunk && $(MAKE) clean
-	cd ../trunk && $(MAKE) lib
+	cd ../trunk && scons libregfi
 
 $(REGFI_THREADTEST): regfi-threadtest.o
Index: test/pyregfi-smoketest.py
===================================================================
--- test/pyregfi-smoketest.py	(revision 227)
+++ test/pyregfi-smoketest.py	(revision 228)
@@ -5,4 +5,5 @@
 import io
 import time
+import threading
 import pyregfi
 
@@ -189,4 +190,32 @@
         pass
 
+
+def threadIterMain(iter):
+    x = 0
+    try:
+        for k in iter:
+            #x += len(k.name) + len(k.subkeys)
+            pass
+    except Exception as e:
+        print("%s dying young: %s" % (threading.current_thread().name, repr(e)))
+        # Exceptions are thrown on iteration because python state gets out of 
+        # whack.  That's fine, because we're really just interested in finding
+        # segfaults.  People should not use iterators without locks, but it 
+        # should at least not segfault on them.
+        pass
+    print("%s finished" % threading.current_thread().name)
+
+def iterMultithread(hive, fh):
+    num_threads = 10
+    iter = pyregfi.HiveIterator(hive)
+    threads = []
+    for t in range(0,num_threads):
+        threads.append(threading.Thread(target=threadIterMain, args=(iter,)))
+    for t in threads:
+        t.start()
+    for t in threads:
+        t.join()
+    
+
 tests = {
     "iterTallyNames":iterTallyNames,
@@ -197,4 +226,5 @@
     "iterIterWalk":iterIterWalk,
     "iterCallbackIO":iterCallbackIO,
+    "iterMultithread":iterMultithread,
     }
 
Index: test/regfi-threadtest.c
===================================================================
--- test/regfi-threadtest.c	(revision 227)
+++ test/regfi-threadtest.c	(revision 228)
@@ -2,5 +2,5 @@
  * A program to stress test regfi under multithreaded use.
  *
- * Copyright (C) 2005-2010 Timothy D. Morgan
+ * Copyright (C) 2005-2011 Timothy D. Morgan
  * Copyright (C) 2002 Richard Sharpe, rsharpe@richardsharpe.com
  *
@@ -46,15 +46,16 @@
 
 
-
 void traverseValueList(REGFI_ITERATOR* iter)
 {
-  const REGFI_VK_REC* value;
-
-  value = regfi_iterator_first_value(iter);
-  while(value != NULL)
-  {
+  const REGFI_VK* value;
+  bool ret;
+
+  for(ret=regfi_iterator_first_value(iter); 
+      ret; 
+      ret=regfi_iterator_next_value(iter))
+  {
+    value = regfi_iterator_cur_value(iter);
     printMsgs(iter->f);
     regfi_free_record(value);
-    value = regfi_iterator_next_value(iter);
   }
 }
@@ -63,12 +64,13 @@
 void traverseKeyTree(REGFI_ITERATOR* iter)
 {
-  const REGFI_NK_REC* root = NULL;
-  const REGFI_NK_REC* cur = NULL;
-  const REGFI_NK_REC* sub = NULL;
-  const REGFI_SK_REC* sk;
+  const REGFI_NK* root = NULL;
+  const REGFI_NK* cur = NULL;
+  const REGFI_NK* sub = NULL;
+  const REGFI_SK* sk;
   bool print_this = true;
 
   root = cur = regfi_iterator_cur_key(iter);
-  sub = regfi_iterator_first_subkey(iter);
+  regfi_iterator_first_subkey(iter);
+  sub = regfi_iterator_cur_subkey(iter);
   printMsgs(iter->f);
 
@@ -86,4 +88,5 @@
       {
 	/* We're done with this sub-tree, going up and hitting other branches. */
+        regfi_free_record(cur);
 	if(!regfi_iterator_up(iter))
 	{
@@ -95,10 +98,12 @@
 	/*	fprintf(stderr, "%s\n", cur->keyname);*/
 	printMsgs(iter->f);
-	sk = regfi_iterator_cur_sk(iter);
-	printMsgs(iter->f);
 	if(cur == NULL)
 	  bailOut(REGLOOKUP_EXIT_DATAERR, "ERROR: unexpected NULL for key.\n");
-      
-	sub = regfi_iterator_next_subkey(iter);
+	sk = regfi_fetch_sk(iter->f, cur);
+	printMsgs(iter->f);
+        regfi_free_record(sk);
+
+	regfi_iterator_next_subkey(iter);
+	sub = regfi_iterator_cur_subkey(iter);
       }
       print_this = false;
@@ -108,4 +113,5 @@
        * Let's move down and print this first sub-tree out. 
        */
+      regfi_free_record(cur);
       if(!regfi_iterator_down(iter))
       {
@@ -118,5 +124,6 @@
       regfi_free_record(sub);
 
-      sub = regfi_iterator_first_subkey(iter);
+      regfi_iterator_first_subkey(iter);
+      sub = regfi_iterator_cur_subkey(iter);
       printMsgs(iter->f);
       print_this = true;
@@ -124,4 +131,5 @@
     printMsgs(iter->f);
   } while(!((cur == root) && (sub == NULL)));
+  regfi_free_record(root);
 
   if(print_verbose)
@@ -138,5 +146,5 @@
   regfi_log_set_mask(REGFI_LOG_INFO|REGFI_LOG_WARN|REGFI_LOG_ERROR);
 
-  iter = regfi_iterator_new((REGFI_FILE*)f, REGFI_ENCODING_ASCII);
+  iter = regfi_iterator_new((REGFI_FILE*)f);
   if(iter == NULL)
   {
@@ -198,5 +206,5 @@
   }
 
-  f = regfi_alloc(fd);
+  f = regfi_alloc(fd, REGFI_ENCODING_ASCII);
   if(f == NULL)
   {
@@ -214,4 +222,5 @@
     pthread_join(threads[i], NULL);
 
+  free(threads);
   regfi_free(f);
   close(fd);
