Index: trunk/src/reglookup-recover.c
===================================================================
--- trunk/src/reglookup-recover.c	(revision 149)
+++ trunk/src/reglookup-recover.c	(revision 150)
@@ -15,5 +15,5 @@
  * You should have received a copy of the GNU General Public License
  * along with this program; if not, write to the Free Software
- * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.  
+ * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  *
  * $Id$
@@ -84,5 +84,6 @@
     quoted_name = malloc(1*sizeof(char));
     if(quoted_name == NULL)
-      bailOut(REGLOOKUP_EXIT_OSERR, "ERROR: Could not allocate sufficient memory.\n");
+      bailOut(REGLOOKUP_EXIT_OSERR, 
+	      "ERROR: Could not allocate sufficient memory.\n");
     quoted_name[0] = '\0';
 
@@ -297,5 +298,5 @@
 	  virt_offset = cur_ancestor->parent_off;
 	
-	path_element = (struct name_holder*)malloc(sizeof(struct name_holder));
+	path_element = talloc(path_stack, struct name_holder);
 	if(path_element != NULL)
 	  path_element->quoted_name = quote_string(cur_ancestor->keyname, 
@@ -305,7 +306,7 @@
 	   || !void_stack_push(path_stack, path_element))
 	{
-	  free(cur_ancestor->keyname);
-	  free(cur_ancestor);
-	  void_stack_free_deep(path_stack);
+	  /* XXX: Need to add a warning here */
+	  regfi_free_key(cur_ancestor);
+	  void_stack_free(path_stack);
 	  return NULL;
 	}
@@ -318,5 +319,5 @@
 	ret_val_size += path_element->length + 1;
 
-	regfi_key_free(cur_ancestor);
+	regfi_free_key(cur_ancestor);
       }
     }
@@ -328,5 +329,5 @@
   if(ret_val == NULL)
   {
-    void_stack_free_deep(path_stack);
+    void_stack_free(path_stack);
     return NULL;
   }
@@ -340,5 +341,5 @@
     ret_val_used += path_element->length + 1;
     free(path_element->quoted_name);
-    free(path_element);
+    talloc_free(path_element);
   }
   void_stack_free(path_stack);
@@ -532,4 +533,5 @@
   REGFI_NK_REC* key;
   uint32 i, j;
+  int error_code = 0;
 
   for(i=0; i < range_list_size(unalloc_cells); i++)
@@ -550,6 +552,8 @@
 	{
 	  fprintf(stderr, "ERROR: Couldn't add key to unalloc_keys.\n");
-	  return 20;
+	  error_code = 20;
+	  goto fail;
 	}
+	talloc_steal(unalloc_keys, key);
 	j+=key->cell_size-8;
       }
@@ -561,8 +565,15 @@
     cur_elem = range_list_get(unalloc_keys, i);
     if(!removeRange(unalloc_cells, cur_elem->offset, cur_elem->length))
-      return 30;
+    {
+      error_code = 30;
+      goto fail;
+    }
   }
 
   return 0;
+
+ fail:
+  regfi_free_key(key);
+  return error_code;
 }
 
@@ -611,6 +622,5 @@
 	     * so prune it.
 	     */
-	    free(nk->values->elements);
-	    free(nk->values);
+	    talloc_free(nk->values);
 	    nk->values = NULL;
 	  }
@@ -639,5 +649,5 @@
 				     vk->cell_size, vk))
 		  {
-		    free(vk);
+		    talloc_free(vk);
 		    return 30;
 		  }
@@ -647,5 +657,5 @@
 		}
 		else
-		  free(vk);
+		  talloc_free(vk);
 	      }
 	    }
Index: trunk/src/reglookup.c
===================================================================
--- trunk/src/reglookup.c	(revision 149)
+++ trunk/src/reglookup.c	(revision 150)
@@ -275,5 +275,5 @@
 void printValueList(REGFI_ITERATOR* iter, char* prefix)
 {
-  const REGFI_VK_REC* value;
+  REGFI_VK_REC* value;
 
   value = regfi_iterator_first_value(iter);
@@ -282,4 +282,5 @@
     if(!type_filter_enabled || (value->type == type_filter))
       printValue(value, prefix);
+    regfi_free_value(value);
     value = regfi_iterator_next_value(iter);
     printMsgs(iter->f);
@@ -373,5 +374,5 @@
   const REGFI_NK_REC* root = NULL;
   const REGFI_NK_REC* cur = NULL;
-  const REGFI_NK_REC* sub = NULL;
+  REGFI_NK_REC* sub = NULL;
   char* path = NULL;
   int key_type = regfi_type_str2val("KEY");
@@ -418,5 +419,5 @@
 	  bailOut(REGLOOKUP_EXIT_DATAERR, "ERROR: unexpected NULL for key.\n");
 	}
-
+	
 	sub = regfi_iterator_next_subkey(iter);
       }
@@ -433,5 +434,6 @@
       }
 
-      cur = sub;
+      cur = regfi_iterator_cur_key(iter);
+      regfi_free_key(sub);
       sub = regfi_iterator_first_subkey(iter);
       print_this = true;
@@ -456,5 +458,5 @@
 int retrievePath(REGFI_ITERATOR* iter, char** path)
 {
-  const REGFI_VK_REC* value;
+  REGFI_VK_REC* value;
   char* tmp_path_joined;
   const char** tmp_path;
@@ -511,4 +513,5 @@
       printValue(value, tmp_path_joined);
 
+    regfi_free_value(value);
     free(tmp_path);
     free(tmp_path_joined);
