Index: /trunk/include/regfi.h
===================================================================
--- /trunk/include/regfi.h	(revision 183)
+++ /trunk/include/regfi.h	(revision 184)
@@ -78,4 +78,7 @@
 #include "lru_cache.h"
 
+
+/******************************************************************************/
+/* Constants for use while interacting with the library                       */
 /******************************************************************************/
 
@@ -84,7 +87,4 @@
 #define REGFI_LOG_WARN  0x0004
 #define REGFI_LOG_ERROR 0x0010
-
-/* For internal use */
-pthread_key_t REGFI_LOG_KEY;
 
 typedef uint8_t REGFI_ENCODING;
@@ -119,4 +119,12 @@
 
 
+
+/******************************************************************************/
+/* Various resource limits and related constants                              */
+/******************************************************************************/
+
+/* Flags determining whether or not to cache various record types internally */
+#define REGFI_CACHE_SK             0
+
 /* This maximum depth is described here:
  * http://msdn.microsoft.com/en-us/library/ms724872%28VS.85%29.aspx
@@ -132,4 +140,11 @@
 #define REGFI_MAX_SUBKEY_DEPTH     255
 
+
+/******************************************************************************/
+/* Symbols for internal use                                                   */
+/******************************************************************************/
+
+/* Global thread-local storage key */
+pthread_key_t REGFI_LOG_KEY;
 
 /* Header sizes and magic number lengths for various records */
@@ -236,4 +251,10 @@
 #define TIME_FIXUP_CONSTANT (369.0*365.25*24*60*60-(3.0*24*60*60+6.0*60*60))
 
+
+
+/******************************************************************************/
+/* Structures                                                                 */
+/******************************************************************************/
+
 typedef struct _regfi_nttime
 {
@@ -825,5 +846,5 @@
  *
  * @return A reference to a newly allocated REGFI_FILE structure, if successful;
- *         NULL on error.
+ *         NULL on error.  Use regfi_free to free the returned REGFI_FILE.
  *
  * @ingroup regfiBase
@@ -840,5 +861,5 @@
  *
  * @return A reference to a newly allocated REGFI_FILE structure, if successful;
- *         NULL on error.
+ *         NULL on error.  Use regfi_free to free the returned REGFI_FILE.
  *
  * @ingroup regfiBase
@@ -909,21 +930,17 @@
 /* Dispose of previously parsed records */
 
-/** Frees a key structure previously returned by one of the API functions
- *
- * XXX: finish documenting
+/** Frees a record previously returned by one of the API functions.
+ *
+ * Can be used to free REGFI_NK_REC, REGFI_VK_REC, REGFI_SK_REC, REGFI_DATA, and
+ * REGFI_CLASSNAME records.
+ *
+ * @note The "const" in the data type is a bit misleading and is there just for
+ * convenience.  Since records returned previously must not be modified by users
+ * of the API due to internal caching, these are returned as const, so this
+ * function is const to make passing back in easy.
  *
  * @ingroup regfiBase
  */
-void                  regfi_free_key(REGFI_NK_REC* nk);
-
-
-/** Frees a value structure previously returned by one of the API functions
- *
- * XXX: finish documenting
- *
- * @ingroup regfiBase
- */
-void                  regfi_free_value(REGFI_VK_REC* vk);
-
+void regfi_free_record(const void* record);
 
 
@@ -1038,5 +1055,5 @@
  * @ingroup regfiIteratorLayer
  */
-const REGFI_NK_REC*   regfi_iterator_cur_key(REGFI_ITERATOR* i);
+const REGFI_NK_REC* regfi_iterator_cur_key(REGFI_ITERATOR* i);
 
 
@@ -1049,5 +1066,5 @@
  * @ingroup regfiIteratorLayer
  */
-const REGFI_SK_REC*   regfi_iterator_cur_sk(REGFI_ITERATOR* i);
+const REGFI_SK_REC* regfi_iterator_cur_sk(REGFI_ITERATOR* i);
 
 
@@ -1060,9 +1077,9 @@
  *         subkey, or NULL on failure.  Failure may be due to a lack of any
  *         subkeys or other errors.  Newly allocated keys must be freed with
- *         regfi_free_key.
- *
- * @ingroup regfiIteratorLayer
- */
-REGFI_NK_REC*         regfi_iterator_first_subkey(REGFI_ITERATOR* i);
+ *         regfi_free_record.
+ *
+ * @ingroup regfiIteratorLayer
+ */
+const REGFI_NK_REC* regfi_iterator_first_subkey(REGFI_ITERATOR* i);
 
 
@@ -1073,9 +1090,9 @@
  * @return A newly allocated key structure for the currently referenced subkey,
  *         or NULL on failure.  Newly allocated keys must be freed with 
- *         regfi_free_key.
- *
- * @ingroup regfiIteratorLayer
- */
-REGFI_NK_REC*         regfi_iterator_cur_subkey(REGFI_ITERATOR* i);
+ *         regfi_free_record.
+ *
+ * @ingroup regfiIteratorLayer
+ */
+const REGFI_NK_REC* regfi_iterator_cur_subkey(REGFI_ITERATOR* i);
 
 
@@ -1086,9 +1103,9 @@
  *
  * @return A newly allocated key structure for the next subkey or NULL on
- *         failure.  Newly allocated keys must be freed with regfi_free_key.
- *
- * @ingroup regfiIteratorLayer
- */
-REGFI_NK_REC*         regfi_iterator_next_subkey(REGFI_ITERATOR* i);
+ *         failure.  Newly allocated keys must be freed with regfi_free_record.
+ *
+ * @ingroup regfiIteratorLayer
+ */
+const REGFI_NK_REC* regfi_iterator_next_subkey(REGFI_ITERATOR* i);
 
 
@@ -1104,6 +1121,6 @@
  * @ingroup regfiIteratorLayer
  */
-bool                  regfi_iterator_find_subkey(REGFI_ITERATOR* i, 
-						 const char* subkey_name);
+bool regfi_iterator_find_subkey(REGFI_ITERATOR* i, const char* subkey_name);
+
 
 /** Sets the internal value index to the first value referenced by the current
@@ -1115,9 +1132,9 @@
  *          value, or NULL on failure.  Failure may be due to a lack of any
  *          values or other errors.  Newly allocated keys must be freed with
- *          regfi_free_value.
- *
- * @ingroup regfiIteratorLayer
- */
-REGFI_VK_REC*         regfi_iterator_first_value(REGFI_ITERATOR* i);
+ *          regfi_free_record.
+ *
+ * @ingroup regfiIteratorLayer
+ */
+const REGFI_VK_REC* regfi_iterator_first_value(REGFI_ITERATOR* i);
 
 
@@ -1128,9 +1145,9 @@
  * @return A newly allocated value structure for the currently referenced value,
  *         or NULL on failure.  Newly allocated values must be freed with 
- *         regfi_free_value.
- *
- * @ingroup regfiIteratorLayer
- */
-REGFI_VK_REC*         regfi_iterator_cur_value(REGFI_ITERATOR* i);
+ *         regfi_free_record.
+ *
+ * @ingroup regfiIteratorLayer
+ */
+const REGFI_VK_REC* regfi_iterator_cur_value(REGFI_ITERATOR* i);
 
 
@@ -1141,9 +1158,9 @@
  *
  * @return  A newly allocated key structure for the next value or NULL on 
- *          failure.  Newly allocated keys must be freed with regfi_free_value.
- *
- * @ingroup regfiIteratorLayer
- */
-REGFI_VK_REC*         regfi_iterator_next_value(REGFI_ITERATOR* i);
+ *          failure.  Newly allocated keys must be freed with regfi_free_record.
+ *
+ * @ingroup regfiIteratorLayer
+ */
+const REGFI_VK_REC* regfi_iterator_next_value(REGFI_ITERATOR* i);
 
 
@@ -1168,10 +1185,10 @@
  *
  * @return Returns a newly allocated classname structure, or NULL on failure.
- *         Classname structures must be freed with regfi_free_classname.
- *
- * @ingroup regfiIteratorLayer
- */
-REGFI_CLASSNAME*      regfi_iterator_fetch_classname(REGFI_ITERATOR* i, 
-						     const REGFI_NK_REC* key);
+ *         Classname structures must be freed with regfi_free_record.
+ *
+ * @ingroup regfiIteratorLayer
+ */
+const REGFI_CLASSNAME* regfi_iterator_fetch_classname(REGFI_ITERATOR* i, 
+						      const REGFI_NK_REC* key);
 
 
@@ -1182,10 +1199,10 @@
  *
  * @return Returns a newly allocated data structure, or NULL on failure.
- *         Data structures must be freed with regfi_free_data.
- *
- * @ingroup regfiIteratorLayer
- */
-REGFI_DATA*           regfi_iterator_fetch_data(REGFI_ITERATOR* i, 
-						const REGFI_VK_REC* value);
+ *         Data structures must be freed with regfi_free_record.
+ *
+ * @ingroup regfiIteratorLayer
+ */
+const REGFI_DATA* regfi_iterator_fetch_data(REGFI_ITERATOR* i,
+					    const REGFI_VK_REC* value);
 
 
@@ -1276,21 +1293,4 @@
 					   uint32_t type, REGFI_DATA* data);
 
-
-/** Frees the memory associated with a REGFI_CLASSNAME data structure.
- *
- * XXX: finish documenting
- *
- * @ingroup regfiGlueLayer
- */
-void                  regfi_free_classname(REGFI_CLASSNAME* classname);
-
-
-/** Frees the memory associated with a REGFI_DATA data structure.
- *
- * XXX: finish documenting
- *
- * @ingroup regfiGlueLayer
- */
-void                  regfi_free_data(REGFI_DATA* data);
 
 
@@ -1434,5 +1434,4 @@
 REGFI_NK_REC*         regfi_rootkey(REGFI_FILE* file, 
 				    REGFI_ENCODING output_encoding);
-void                  regfi_subkeylist_free(REGFI_SUBKEY_LIST* list);
 
 off_t                 regfi_raw_seek(REGFI_RAW_FILE* self, 
Index: /trunk/lib/lru_cache.c
===================================================================
--- /trunk/lib/lru_cache.c	(revision 183)
+++ /trunk/lib/lru_cache.c	(revision 184)
@@ -119,4 +119,6 @@
   if(max_keys == 0)
     ret_val->num_buckets = 1024;
+  else if(max_keys == 1)
+    ret_val->num_buckets = 1;    
   else
   {
@@ -125,5 +127,5 @@
       ret_val->num_buckets = 1;
   }
-
+  
   ret_val->table = talloc_array(ret_val, 
 				lru_cache_element*, ret_val->num_buckets);
@@ -177,5 +179,5 @@
      */
     if(ht->talloc_data)
-      talloc_free(e->data);
+      talloc_unlink(e, e->data);
 
     if(e->newer == NULL)
@@ -224,5 +226,5 @@
 
       if(ht->talloc_data)
-	talloc_free(e->data);
+	talloc_unlink(e, e->data);
 
       tmp_index = talloc_realloc_size(e, e->index, index_len);
@@ -261,5 +263,5 @@
   e->data = data;
   if(ht->talloc_data)
-    talloc_steal(e, e->data);
+    talloc_reference(e, e->data);
 
   /* Finally, let's insert the element to the newest position in the LRU list.*/
Index: /trunk/lib/regfi.c
===================================================================
--- /trunk/lib/regfi.c	(revision 183)
+++ /trunk/lib/regfi.c	(revision 184)
@@ -947,5 +947,5 @@
   
   for(i=0; i < num_lists; i++)
-    regfi_subkeylist_free(lists[i]);
+    talloc_free(lists[i]);
   free(lists);
 
@@ -1185,5 +1185,5 @@
     if(vk->valuename == NULL)
     {
-      regfi_free_value(vk);
+      talloc_free(vk);
       return;
     }
@@ -1279,5 +1279,5 @@
     if(nk->keyname == NULL)
     {
-      regfi_free_key(nk);
+      talloc_free(nk);
       return;
     }
@@ -1333,5 +1333,5 @@
       if(strict)
       {
-	regfi_free_key(nk);
+	talloc_free(nk);
 	return NULL;
       }
@@ -1350,5 +1350,5 @@
 	if(strict)
 	{
-	  regfi_free_key(nk);
+	  talloc_free(nk);
 	  return NULL;
 	}
@@ -1367,5 +1367,5 @@
       if(strict)
       {
-	regfi_free_key(nk);
+	talloc_free(nk);
 	return NULL;
       }
@@ -1400,4 +1400,11 @@
   void* failure_ptr = NULL;
   
+  max_size = regfi_calc_maxsize(file, offset);
+  if(max_size < 0)
+    return NULL;
+
+  if(file->sk_cache == NULL)
+    return regfi_parse_sk(file, offset, max_size, strict);
+
   if(!regfi_lock(file, file->sk_lock, "regfi_load_sk"))
     return NULL;
@@ -1412,8 +1419,4 @@
   if(ret_val == NULL)
   {
-    max_size = regfi_calc_maxsize(file, offset);
-    if(max_size < 0)
-      return NULL;
-
     ret_val = regfi_parse_sk(file, offset, max_size, strict);
     if(ret_val == NULL)
@@ -1424,12 +1427,16 @@
       *(uint32_t*)failure_ptr = REGFI_OFFSET_NONE;
       lru_cache_update(file->sk_cache, &offset, 4, failure_ptr);
+
+      /* Let the cache be the only owner of this */
+      talloc_unlink(NULL, failure_ptr);
       return NULL;
     }
-
-    lru_cache_update(file->sk_cache, &offset, 4, ret_val);
   }
 
   if(!regfi_unlock(file, file->sk_lock, "regfi_load_sk"))
-    return NULL;
+  {
+    talloc_unlink(NULL, ret_val);
+    return NULL;
+  }
 
   return ret_val;
@@ -1597,6 +1604,8 @@
   cache_secret = 0x15DEAD05^time(NULL)^(getpid()<<16);
 
-  /* Cache an unlimited number of SK records.  Typically there are very few. */
-  rb->sk_cache = lru_cache_create_ctx(rb, 0, cache_secret, true);
+  if(REGFI_CACHE_SK)
+    rb->sk_cache = lru_cache_create_ctx(rb, 64, cache_secret, true);
+  else
+    rb->sk_cache = NULL;
 
   /* success */
@@ -1678,28 +1687,9 @@
 /******************************************************************************
  *****************************************************************************/
-void regfi_free_key(REGFI_NK_REC* nk)
-{
-  regfi_subkeylist_free(nk->subkeys);
-  talloc_free(nk);
-}
-
-
-/******************************************************************************
- *****************************************************************************/
-void regfi_free_value(REGFI_VK_REC* vk)
-{
-  talloc_free(vk);
-}
-
-
-/******************************************************************************
- *****************************************************************************/
-void regfi_subkeylist_free(REGFI_SUBKEY_LIST* list)
-{
-  if(list != NULL)
-  {
-    talloc_free(list);
-  }
-}
+void regfi_free_record(const void* record)
+{
+  talloc_unlink(NULL, (void*)record);
+}
+
 
 
@@ -1731,5 +1721,5 @@
   }
   ret_val->cur_key = root;
-  talloc_steal(ret_val, root);
+  talloc_reference(ret_val, root);
 
   ret_val->key_positions = void_stack_new(REGFI_MAX_DEPTH);
@@ -1783,8 +1773,8 @@
   {
     talloc_free(pos);
-    regfi_free_key(subkey);
+    talloc_unlink(NULL, subkey);
     return false;
   }
-  talloc_steal(i, subkey);
+  talloc_reference(i, subkey);
 
   i->cur_key = subkey;
@@ -1806,5 +1796,5 @@
     return false;
 
-  regfi_free_key(i->cur_key);
+  talloc_unlink(i, i->cur_key);
   i->cur_key = pos->nk;
   i->cur_subkey = pos->cur_subkey;
@@ -1847,5 +1837,5 @@
     else
     {
-      regfi_free_key(subkey);
+      talloc_unlink(NULL, subkey);
       subkey = (REGFI_NK_REC*)regfi_iterator_next_subkey(i);
     }
@@ -1858,5 +1848,5 @@
   }
 
-  regfi_free_key(subkey);
+  talloc_unlink(NULL, subkey);
   return true;
 }
@@ -1909,5 +1899,5 @@
 /******************************************************************************
  *****************************************************************************/
-REGFI_NK_REC* regfi_iterator_first_subkey(REGFI_ITERATOR* i)
+const REGFI_NK_REC* regfi_iterator_first_subkey(REGFI_ITERATOR* i)
 {
   i->cur_subkey = 0;
@@ -1918,5 +1908,5 @@
 /******************************************************************************
  *****************************************************************************/
-REGFI_NK_REC* regfi_iterator_cur_subkey(REGFI_ITERATOR* i)
+const REGFI_NK_REC* regfi_iterator_cur_subkey(REGFI_ITERATOR* i)
 {
   uint32_t nk_offset;
@@ -1929,6 +1919,6 @@
   nk_offset = i->cur_key->subkeys->elements[i->cur_subkey].offset;
 
-  return regfi_load_key(i->f, nk_offset+REGFI_REGF_SIZE, i->string_encoding, 
-			true);
+  return regfi_load_key(i->f, nk_offset+REGFI_REGF_SIZE, 
+			i->string_encoding, true);
 }
 
@@ -1937,7 +1927,7 @@
  *****************************************************************************/
 /* XXX: some way of indicating reason for failure should be added. */
-REGFI_NK_REC* regfi_iterator_next_subkey(REGFI_ITERATOR* i)
-{
-  REGFI_NK_REC* subkey;
+const REGFI_NK_REC* regfi_iterator_next_subkey(REGFI_ITERATOR* i)
+{
+  const REGFI_NK_REC* subkey;
 
   i->cur_subkey++;
@@ -1955,5 +1945,5 @@
 bool regfi_iterator_find_value(REGFI_ITERATOR* i, const char* value_name)
 {
-  REGFI_VK_REC* cur;
+  const REGFI_VK_REC* cur;
   bool found = false;
   uint32_t old_value = i->cur_value;
@@ -1973,5 +1963,5 @@
     else
     {
-      regfi_free_value(cur);
+      regfi_free_record(cur);
       cur = regfi_iterator_next_value(i);
     }
@@ -1984,5 +1974,5 @@
   }
 
-  regfi_free_value(cur);
+  regfi_free_record(cur);
   return true;
 }
@@ -1991,5 +1981,5 @@
 /******************************************************************************
  *****************************************************************************/
-REGFI_VK_REC* regfi_iterator_first_value(REGFI_ITERATOR* i)
+const REGFI_VK_REC* regfi_iterator_first_value(REGFI_ITERATOR* i)
 {
   i->cur_value = 0;
@@ -2000,5 +1990,5 @@
 /******************************************************************************
  *****************************************************************************/
-REGFI_VK_REC* regfi_iterator_cur_value(REGFI_ITERATOR* i)
+const REGFI_VK_REC* regfi_iterator_cur_value(REGFI_ITERATOR* i)
 {
   REGFI_VK_REC* ret_val = NULL;
@@ -2021,7 +2011,7 @@
 /******************************************************************************
  *****************************************************************************/
-REGFI_VK_REC* regfi_iterator_next_value(REGFI_ITERATOR* i)
-{
-  REGFI_VK_REC* ret_val;
+const REGFI_VK_REC* regfi_iterator_next_value(REGFI_ITERATOR* i)
+{
+  const REGFI_VK_REC* ret_val;
 
   i->cur_value++;
@@ -2036,6 +2026,6 @@
 /******************************************************************************
  *****************************************************************************/
-REGFI_CLASSNAME* regfi_iterator_fetch_classname(REGFI_ITERATOR* i, 
-						const REGFI_NK_REC* key)
+const REGFI_CLASSNAME* regfi_iterator_fetch_classname(REGFI_ITERATOR* i,
+						      const REGFI_NK_REC* key)
 {
   REGFI_CLASSNAME* ret_val;
@@ -2100,6 +2090,6 @@
 /******************************************************************************
  *****************************************************************************/
-REGFI_DATA* regfi_iterator_fetch_data(REGFI_ITERATOR* i, 
-				      const REGFI_VK_REC* value)
+const REGFI_DATA* regfi_iterator_fetch_data(REGFI_ITERATOR* i, 
+					    const REGFI_VK_REC* value)
 {
   REGFI_DATA* ret_val = NULL;
@@ -2140,19 +2130,4 @@
   
   return ret_val;
-}
-
-
-/******************************************************************************
- *****************************************************************************/
-void regfi_free_classname(REGFI_CLASSNAME* classname)
-{
-  talloc_free(classname);
-}
-
-/******************************************************************************
- *****************************************************************************/
-void regfi_free_data(REGFI_DATA* data)
-{
-  talloc_free(data);
 }
 
Index: /trunk/src/common.c
===================================================================
--- /trunk/src/common.c	(revision 183)
+++ /trunk/src/common.c	(revision 184)
@@ -163,5 +163,5 @@
  * value, and a non-NULL (*error_msg).
  */
-static char* data_to_ascii(REGFI_DATA* data, char** error_msg)
+static char* data_to_ascii(const REGFI_DATA* data, char** error_msg)
 {
   char* ret_val;
Index: /trunk/src/reglookup-recover.c
===================================================================
--- /trunk/src/reglookup-recover.c	(revision 183)
+++ /trunk/src/reglookup-recover.c	(revision 184)
@@ -291,5 +291,5 @@
 	{
 	  /* XXX: Need to add a warning here */
-	  regfi_free_key(cur_ancestor);
+	  regfi_free_record(cur_ancestor);
 	  void_stack_free(path_stack);
 	  return NULL;
@@ -303,5 +303,5 @@
 	ret_val_size += path_element->len + 1;
 
-	regfi_free_key(cur_ancestor);
+	regfi_free_record(cur_ancestor);
       }
     }
@@ -631,5 +631,5 @@
 
  fail:
-  regfi_free_key(key);
+  regfi_free_record(key);
   return error_code;
 }
Index: /trunk/src/reglookup.c
===================================================================
--- /trunk/src/reglookup.c	(revision 183)
+++ /trunk/src/reglookup.c	(revision 184)
@@ -54,5 +54,5 @@
 void printValue(REGFI_ITERATOR* iter, const REGFI_VK_REC* vk, char* prefix)
 {
-  REGFI_DATA* data;
+  const REGFI_DATA* data;
   char* quoted_value = NULL;
   char* quoted_name = NULL;
@@ -95,5 +95,5 @@
       fprintf(stderr, "WARN: While quoting value for '%s/%s', "
 	      "warning returned: %s\n", prefix, quoted_name, conv_error);
-    regfi_free_data(data);
+    regfi_free_record(data);
   }
 
@@ -275,5 +275,5 @@
 void printValueList(REGFI_ITERATOR* iter, char* prefix)
 {
-  REGFI_VK_REC* value;
+  const REGFI_VK_REC* value;
 
   value = regfi_iterator_first_value(iter);
@@ -282,5 +282,5 @@
     if(!type_filter_enabled || (value->type == type_filter))
       printValue(iter, value, prefix);
-    regfi_free_value(value);
+    regfi_free_record(value);
     value = regfi_iterator_next_value(iter);
     printMsgs(iter->f);
@@ -299,8 +299,8 @@
   char* quoted_classname;
   const REGFI_SK_REC* sk;
-  const REGFI_NK_REC* k = regfi_iterator_cur_key(iter);
-  REGFI_CLASSNAME* classname;
-
-  formatTime(&k->mtime, mtime);
+  const REGFI_NK_REC* key = regfi_iterator_cur_key(iter);
+  const REGFI_CLASSNAME* classname;
+
+  formatTime(&key->mtime, mtime);
 
   if(print_security && (sk=regfi_iterator_cur_sk(iter)))
@@ -310,4 +310,6 @@
     sacl = regfi_get_sacl(sk->sec_desc);
     dacl = regfi_get_dacl(sk->sec_desc);
+    regfi_free_record(sk);
+
     if(owner == NULL)
       owner = empty_str;
@@ -319,5 +321,5 @@
       dacl = empty_str;
 
-    classname = regfi_iterator_fetch_classname(iter, k);
+    classname = regfi_iterator_fetch_classname(iter, key);
     printMsgs(iter->f);
     if(classname != NULL)
@@ -343,5 +345,5 @@
     else
       quoted_classname = empty_str;
-    regfi_free_classname(classname);
+    regfi_free_record(classname);
 
     printMsgs(iter->f);
@@ -362,4 +364,6 @@
   else
     printf("%s,KEY,,%s\n", full_path, mtime);
+
+  regfi_free_record(key);
 }
 
@@ -369,5 +373,5 @@
   const REGFI_NK_REC* root = NULL;
   const REGFI_NK_REC* cur = NULL;
-  REGFI_NK_REC* sub = NULL;
+  const REGFI_NK_REC* sub = NULL;
   char* path = NULL;
   int key_type = regfi_type_str2val("KEY");
@@ -430,5 +434,5 @@
 
       cur = regfi_iterator_cur_key(iter);
-      regfi_free_key(sub);
+      regfi_free_record(sub);
       sub = regfi_iterator_first_subkey(iter);
       print_this = true;
@@ -453,5 +457,5 @@
 int retrievePath(REGFI_ITERATOR* iter, char** path)
 {
-  REGFI_VK_REC* value;
+  const REGFI_VK_REC* value;
   char* tmp_path_joined;
   const char** tmp_path;
@@ -508,5 +512,5 @@
       printValue(iter, value, tmp_path_joined);
 
-    regfi_free_value(value);
+    regfi_free_record(value);
     free(tmp_path);
     free(tmp_path_joined);
