Index: trunk/include/regfi.h
===================================================================
--- trunk/include/regfi.h	(revision 185)
+++ trunk/include/regfi.h	(revision 186)
@@ -716,5 +716,5 @@
    * the file offset while another thread is in the middle of a multi-read
    * parsing transaction */
-  pthread_mutex_t* cb_lock;
+  pthread_mutex_t cb_lock;
 
   /* For sanity checking (not part of the registry header) */
@@ -725,5 +725,5 @@
 
   /* Multiple read access allowed, write access is exclusive */
-  pthread_rwlock_t* hbins_lock;
+  pthread_rwlock_t hbins_lock;
 
   /* SK record cached since they're repeatedly reused */
@@ -731,5 +731,5 @@
 
   /* Need exclusive access for LRUs, since lookups make changes */
-  pthread_mutex_t* sk_lock;
+  pthread_mutex_t sk_lock;
 
   /* Data parsed from file header */
Index: trunk/lib/regfi.c
===================================================================
--- trunk/lib/regfi.c	(revision 185)
+++ trunk/lib/regfi.c	(revision 186)
@@ -806,5 +806,5 @@
   bool recursive_type;
 
-  if(!regfi_lock(file, file->cb_lock, "regfi_parse_subkeylist"))
+  if(!regfi_lock(file, &file->cb_lock, "regfi_parse_subkeylist"))
      goto fail;
 
@@ -882,5 +882,5 @@
     goto fail_locked;
 
-  if(!regfi_unlock(file, file->cb_lock, "regfi_parse_subkeylist"))
+  if(!regfi_unlock(file, &file->cb_lock, "regfi_parse_subkeylist"))
      goto fail;
 
@@ -906,5 +906,5 @@
 
  fail_locked:
-  regfi_unlock(file, file->cb_lock, "regfi_parse_subkeylist");
+  regfi_unlock(file, &file->cb_lock, "regfi_parse_subkeylist");
  fail:
   if(elements != NULL)
@@ -982,5 +982,5 @@
   bool unalloc = false;
 
-  if(!regfi_lock(file, file->cb_lock, "regfi_parse_sk"))
+  if(!regfi_lock(file, &file->cb_lock, "regfi_parse_sk"))
      goto fail;
 
@@ -1060,5 +1060,5 @@
   }
 
-  if(!regfi_unlock(file, file->cb_lock, "regfi_parse_sk"))
+  if(!regfi_unlock(file, &file->cb_lock, "regfi_parse_sk"))
      goto fail;
 
@@ -1076,5 +1076,5 @@
 
  fail_locked:
-  regfi_unlock(file, file->cb_lock, "regfi_parse_sk");
+  regfi_unlock(file, &file->cb_lock, "regfi_parse_sk");
  fail:
   if(sec_desc_buf != NULL)
@@ -1092,5 +1092,5 @@
   bool unalloc;
 
-  if(!regfi_lock(file, file->cb_lock, "regfi_parse_valuelist"))
+  if(!regfi_lock(file, &file->cb_lock, "regfi_parse_valuelist"))
      goto fail;
 
@@ -1140,5 +1140,5 @@
   }
   
-  if(!regfi_unlock(file, file->cb_lock, "regfi_parse_valuelist"))
+  if(!regfi_unlock(file, &file->cb_lock, "regfi_parse_valuelist"))
      goto fail;
 
@@ -1167,5 +1167,5 @@
 
  fail_locked:
-  regfi_unlock(file, file->cb_lock, "regfi_parse_valuelist");
+  regfi_unlock(file, &file->cb_lock, "regfi_parse_valuelist");
  fail:
   talloc_free(ret_val);
@@ -1423,5 +1423,5 @@
     return regfi_parse_sk(file, offset, max_size, strict);
 
-  if(!regfi_lock(file, file->sk_lock, "regfi_load_sk"))
+  if(!regfi_lock(file, &file->sk_lock, "regfi_load_sk"))
     return NULL;
 
@@ -1450,5 +1450,5 @@
   }
 
-  if(!regfi_unlock(file, file->sk_lock, "regfi_load_sk"))
+  if(!regfi_unlock(file, &file->sk_lock, "regfi_load_sk"))
   {
     talloc_unlink(NULL, ret_val);
@@ -1475,5 +1475,5 @@
   {
 
-    if(!regfi_lock(file, file->cb_lock, "regfi_find_root_nk"))
+    if(!regfi_lock(file, &file->cb_lock, "regfi_find_root_nk"))
       return NULL;
 
@@ -1485,5 +1485,5 @@
     }
 
-    if(!regfi_unlock(file, file->cb_lock, "regfi_find_root_nk"))
+    if(!regfi_unlock(file, &file->cb_lock, "regfi_find_root_nk"))
       return NULL;
 
@@ -1539,5 +1539,20 @@
 
 
-
+/******************************************************************************
+ ******************************************************************************/
+int regfi_free_cb(void* f)
+{
+  REGFI_FILE* file = (REGFI_FILE*)f;
+
+  pthread_mutex_destroy(&file->cb_lock);
+  pthread_rwlock_destroy(&file->hbins_lock);
+  pthread_mutex_destroy(&file->sk_lock);
+
+  return 0;
+}
+
+
+/******************************************************************************
+ ******************************************************************************/
 REGFI_FILE* regfi_alloc_cb(REGFI_RAW_FILE* file_cb)
 {
@@ -1568,10 +1583,6 @@
   rb->file_length = file_length;  
   rb->cb = file_cb;
-  rb->cb_lock = NULL;
-  rb->hbins_lock = NULL;
-  rb->sk_lock = NULL;
-
-  rb->cb_lock = talloc(rb, pthread_mutex_t);
-  if(rb->cb_lock == NULL || pthread_mutex_init(rb->cb_lock, NULL) != 0)
+
+  if(pthread_mutex_init(&rb->cb_lock, NULL) != 0)
   {
     regfi_log_add(REGFI_LOG_ERROR, "Failed to create cb_lock mutex.");
@@ -1579,6 +1590,5 @@
   }
 
-  rb->hbins_lock = talloc(rb, pthread_rwlock_t);
-  if(rb->hbins_lock == NULL || pthread_rwlock_init(rb->hbins_lock, NULL) != 0)
+  if(pthread_rwlock_init(&rb->hbins_lock, NULL) != 0)
   {
     regfi_log_add(REGFI_LOG_ERROR, "Failed to create hbins_lock rwlock.");
@@ -1586,6 +1596,5 @@
   }
 
-  rb->sk_lock = talloc(rb, pthread_mutex_t);
-  if(rb->sk_lock == NULL || pthread_mutex_init(rb->sk_lock, NULL) != 0)
+  if(pthread_mutex_init(&rb->sk_lock, NULL) != 0)
   {
     regfi_log_add(REGFI_LOG_ERROR, "Failed to create sk_lock mutex.");
@@ -1626,17 +1635,13 @@
 
   /* success */
+  talloc_set_destructor(rb, regfi_free_cb);
   return rb;
 
  fail:
-  if(rb->cb_lock != NULL)
-    pthread_mutex_destroy(rb->cb_lock);
-  if(rb->hbins_lock != NULL)
-    pthread_rwlock_destroy(rb->hbins_lock);
-  if(rb->sk_lock != NULL)
-    pthread_mutex_destroy(rb->sk_lock);
+  pthread_mutex_destroy(&rb->cb_lock);
+  pthread_rwlock_destroy(&rb->hbins_lock);
+  pthread_mutex_destroy(&rb->sk_lock);
 
   range_list_free(rb->hbins);
-  talloc_free(rb->cb_lock);
-  talloc_free(rb->hbins_lock);
   talloc_free(rb);
   return NULL;
@@ -1646,9 +1651,7 @@
 /******************************************************************************
  ******************************************************************************/
-void regfi_free(REGFI_FILE *file)
-{
-  pthread_mutex_destroy(file->cb_lock);
-  pthread_rwlock_destroy(file->hbins_lock);
-  pthread_mutex_destroy(file->sk_lock);
+void regfi_free(REGFI_FILE* file)
+{
+  /* Callback handles cleanup side effects */
   talloc_free(file);
 }
@@ -1684,5 +1687,5 @@
    */
   
-  if(!regfi_read_lock(file, file->hbins_lock, "regfi_rootkey"))
+  if(!regfi_read_lock(file, &file->hbins_lock, "regfi_rootkey"))
     return NULL;
 
@@ -1694,5 +1697,5 @@
   }
 
-  if(!regfi_rw_unlock(file, file->hbins_lock, "regfi_rootkey"))
+  if(!regfi_rw_unlock(file, &file->hbins_lock, "regfi_rootkey"))
     return NULL;
 
@@ -2498,5 +2501,5 @@
     goto fail;
   
-  if(!regfi_lock(file, file->cb_lock, "regfi_parse_hbin"))
+  if(!regfi_lock(file, &file->cb_lock, "regfi_parse_hbin"))
     goto fail;
 
@@ -2517,5 +2520,5 @@
   }
 
-  if(!regfi_unlock(file, file->cb_lock, "regfi_parse_hbin"))
+  if(!regfi_unlock(file, &file->cb_lock, "regfi_parse_hbin"))
     goto fail;
 
@@ -2562,5 +2565,5 @@
 
  fail_locked:
-  regfi_unlock(file, file->cb_lock, "regfi_parse_hbin");
+  regfi_unlock(file, &file->cb_lock, "regfi_parse_hbin");
  fail:
   talloc_free(hbin);
@@ -2587,5 +2590,5 @@
   }
 
-  if(!regfi_lock(file, file->cb_lock, "regfi_parse_nk"))
+  if(!regfi_lock(file, &file->cb_lock, "regfi_parse_nk"))
     goto fail;
 
@@ -2700,5 +2703,5 @@
   }
 
-  if(!regfi_unlock(file, file->cb_lock, "regfi_parse_nk"))
+  if(!regfi_unlock(file, &file->cb_lock, "regfi_parse_nk"))
     goto fail;
 
@@ -2706,5 +2709,5 @@
 
  fail_locked:
-  regfi_unlock(file, file->cb_lock, "regfi_parse_nk");
+  regfi_unlock(file, &file->cb_lock, "regfi_parse_nk");
  fail:
   talloc_free(ret_val);
@@ -2725,5 +2728,5 @@
   { goto fail; }
 
-  if(!regfi_lock(file, file->cb_lock, "regfi_parse_classname"))
+  if(!regfi_lock(file, &file->cb_lock, "regfi_parse_classname"))
     goto fail;
 
@@ -2775,5 +2778,5 @@
   }
 
-  if(!regfi_unlock(file, file->cb_lock, "regfi_parse_classname"))
+  if(!regfi_unlock(file, &file->cb_lock, "regfi_parse_classname"))
     goto fail;
 
@@ -2781,5 +2784,5 @@
 
  fail_locked:
-  regfi_unlock(file, file->cb_lock, "regfi_parse_classname");
+  regfi_unlock(file, &file->cb_lock, "regfi_parse_classname");
  fail:
   talloc_free(ret_val);
@@ -2802,5 +2805,5 @@
     goto fail;
 
-  if(!regfi_lock(file, file->cb_lock, "regfi_parse_nk"))
+  if(!regfi_lock(file, &file->cb_lock, "regfi_parse_nk"))
     goto fail;
 
@@ -2887,5 +2890,5 @@
     cell_length = REGFI_VK_MIN_LENGTH + 4;
 
-  if(!regfi_unlock(file, file->cb_lock, "regfi_parse_nk"))
+  if(!regfi_unlock(file, &file->cb_lock, "regfi_parse_nk"))
     goto fail;
 
@@ -2900,5 +2903,5 @@
   
  fail_locked:
-  regfi_unlock(file, file->cb_lock, "regfi_parse_vk");
+  regfi_unlock(file, &file->cb_lock, "regfi_parse_vk");
  fail:
   talloc_free(ret_val);
@@ -2952,5 +2955,5 @@
     }
     
-    if(!regfi_lock(file, file->cb_lock, "regfi_load_data"))
+    if(!regfi_lock(file, &file->cb_lock, "regfi_load_data"))
       goto fail;
 
@@ -2963,5 +2966,5 @@
     }
 
-    if(!regfi_unlock(file, file->cb_lock, "regfi_load_data"))
+    if(!regfi_unlock(file, &file->cb_lock, "regfi_load_data"))
       goto fail;
 
@@ -3013,5 +3016,5 @@
 
  fail_locked:
-  regfi_unlock(file, file->cb_lock, "regfi_load_data");
+  regfi_unlock(file, &file->cb_lock, "regfi_load_data");
  fail:
   ret_val.buf = NULL;
@@ -3037,5 +3040,5 @@
   ret_val.len = length;
 
-  if(!regfi_lock(file, file->cb_lock, "regfi_parse_data"))
+  if(!regfi_lock(file, &file->cb_lock, "regfi_parse_data"))
     goto fail;
 
@@ -3056,5 +3059,5 @@
   }
 
-  if(!regfi_unlock(file, file->cb_lock, "regfi_parse_data"))
+  if(!regfi_unlock(file, &file->cb_lock, "regfi_parse_data"))
     goto fail;
 
@@ -3062,5 +3065,5 @@
 
  fail_locked:
-  regfi_unlock(file, file->cb_lock, "regfi_parse_data");
+  regfi_unlock(file, &file->cb_lock, "regfi_parse_data");
  fail:
   talloc_free(ret_val.buf);
@@ -3123,5 +3126,5 @@
   }
 
-  if(!regfi_lock(file, file->cb_lock, "regfi_parse_big_data_header"))
+  if(!regfi_lock(file, &file->cb_lock, "regfi_parse_big_data_header"))
     goto fail;
 
@@ -3135,5 +3138,5 @@
   }
 
-  if(!regfi_unlock(file, file->cb_lock, "regfi_parse_big_data_header"))
+  if(!regfi_unlock(file, &file->cb_lock, "regfi_parse_big_data_header"))
     goto fail;
 
@@ -3151,5 +3154,5 @@
 
  fail_locked:
-  regfi_unlock(file, file->cb_lock, "regfi_parse_big_data_header");
+  regfi_unlock(file, &file->cb_lock, "regfi_parse_big_data_header");
  fail:
   talloc_free(ret_val.buf);
@@ -3183,5 +3186,5 @@
     goto fail;
 
-  if(!regfi_lock(file, file->cb_lock, "regfi_parse_big_data_indirect"))
+  if(!regfi_lock(file, &file->cb_lock, "regfi_parse_big_data_indirect"))
     goto fail;
 
@@ -3196,5 +3199,5 @@
   }
 
-  if(!regfi_unlock(file, file->cb_lock, "regfi_parse_big_data_indirect"))
+  if(!regfi_unlock(file, &file->cb_lock, "regfi_parse_big_data_indirect"))
     goto fail;
 
@@ -3210,5 +3213,5 @@
 
  fail_locked:
-  regfi_unlock(file, file->cb_lock, "regfi_parse_big_data_indirect");
+  regfi_unlock(file, &file->cb_lock, "regfi_parse_big_data_indirect");
  fail:
   talloc_free(ret_val);
@@ -3244,5 +3247,5 @@
   for(i=0; i<num_chunks; i++)
   {
-    if(!regfi_lock(file, file->cb_lock, "regfi_parse_big_data_cells"))
+    if(!regfi_lock(file, &file->cb_lock, "regfi_parse_big_data_cells"))
       goto fail;
 
@@ -3257,5 +3260,5 @@
     }
 
-    if(!regfi_unlock(file, file->cb_lock, "regfi_parse_big_data_cells"))
+    if(!regfi_unlock(file, &file->cb_lock, "regfi_parse_big_data_cells"))
       goto fail;
 
@@ -3267,5 +3270,5 @@
 
  fail_locked:
-  regfi_unlock(file, file->cb_lock, "regfi_parse_big_data_cells");
+  regfi_unlock(file, &file->cb_lock, "regfi_parse_big_data_cells");
  fail:
   if(ret_val != NULL)
@@ -3361,5 +3364,5 @@
     }
 
-    if(!regfi_lock(file, file->cb_lock, "regfi_load_big_data"))
+    if(!regfi_lock(file, &file->cb_lock, "regfi_load_big_data"))
       goto fail;
 
@@ -3382,5 +3385,5 @@
     }
 
-    if(!regfi_unlock(file, file->cb_lock, "regfi_load_big_data"))
+    if(!regfi_unlock(file, &file->cb_lock, "regfi_load_big_data"))
       goto fail;
 
@@ -3397,5 +3400,5 @@
 
  fail_locked:
-  regfi_unlock(file, file->cb_lock, "regfi_load_big_data");
+  regfi_unlock(file, &file->cb_lock, "regfi_load_big_data");
  fail:
   talloc_free(ret_val.buf);
@@ -3421,5 +3424,5 @@
     return NULL;
 
-  if(!regfi_read_lock(file, file->hbins_lock, "regfi_parse_unalloc_cells"))
+  if(!regfi_read_lock(file, &file->hbins_lock, "regfi_parse_unalloc_cells"))
   {
     range_list_free(ret_val);
@@ -3438,5 +3441,5 @@
     while(curr_off < hbin->block_size)
     {
-      if(!regfi_lock(file, file->cb_lock, "regfi_parse_unalloc_cells"))
+      if(!regfi_lock(file, &file->cb_lock, "regfi_parse_unalloc_cells"))
 	break;
 
@@ -3444,9 +3447,9 @@
 			   &cell_len, &is_unalloc))
       {
-	regfi_unlock(file, file->cb_lock, "regfi_parse_unalloc_cells");
+	regfi_unlock(file, &file->cb_lock, "regfi_parse_unalloc_cells");
 	break;
       }
 
-      if(!regfi_unlock(file, file->cb_lock, "regfi_parse_unalloc_cells"))
+      if(!regfi_unlock(file, &file->cb_lock, "regfi_parse_unalloc_cells"))
 	break;
 
@@ -3474,5 +3477,5 @@
   }
 
-  if(!regfi_rw_unlock(file, file->hbins_lock, "regfi_parse_unalloc_cells"))
+  if(!regfi_rw_unlock(file, &file->hbins_lock, "regfi_parse_unalloc_cells"))
   {
     range_list_free(ret_val);
Index: trunk/src/common.c
===================================================================
--- trunk/src/common.c	(revision 185)
+++ trunk/src/common.c	(revision 186)
@@ -48,5 +48,5 @@
 void bailOut(int code, char* message)
 {
-  fprintf(stderr, message);
+  fprintf(stderr, "%s", message);
   exit(code);
 }
