Index: trunk/python/pyregfi/__init__.py
===================================================================
--- trunk/python/pyregfi/__init__.py	(revision 212)
+++ trunk/python/pyregfi/__init__.py	(revision 213)
@@ -15,8 +15,8 @@
 
 
-regfi.regfi_alloc.argtypes = [c_int]
+regfi.regfi_alloc.argtypes = [c_int, REGFI_ENCODING]
 regfi.regfi_alloc.restype = POINTER(REGFI_FILE)
 
-regfi.regfi_alloc_cb.argtypes = [POINTER(REGFI_RAW_FILE)]
+regfi.regfi_alloc_cb.argtypes = [POINTER(REGFI_RAW_FILE), REGFI_ENCODING]
 regfi.regfi_alloc_cb.restype = POINTER(REGFI_FILE)
 
@@ -140,5 +140,5 @@
     s = chars_pointer[i]
     while s != None:
-        ret_val.append(s.decode('utf-8'))
+        ret_val.append(s.decode('utf-8', 'replace'))
         i += 1
         s = chars_pointer[i]
@@ -150,5 +150,4 @@
 #  access to base structures  
 class _StructureWrapper(object):
-
     hive = None
     base = None
@@ -161,4 +160,5 @@
     def __del__(self):
         regfi.regfi_free_record(self.base)
+        hive = None
 
     def __getattr__(self, name):
@@ -205,4 +205,7 @@
         self.length = self.fetch_num(key.base)
     
+    def __del__(self):
+        self.key = None
+
     def __len__(self):
         return self.length
@@ -274,5 +277,5 @@
                 ret_val = self.name_raw
             else:
-                ret_val = ret_val.decode('utf-8')
+                ret_val = ret_val.decode('utf-8', 'replace')
                 
         elif name == "name_raw":
@@ -307,5 +310,5 @@
             elif data_struct.type in (REG_SZ, REG_EXPAND_SZ, REG_LINK):
                 # Unicode strings
-                ret_val = data_struct.interpreted.string.decode('utf-8')
+                ret_val = data_struct.interpreted.string.decode('utf-8', 'replace')
             elif data_struct.type in (REG_DWORD, REG_DWORD_BE):
                 # 32 bit integers
@@ -343,5 +346,5 @@
                     ret_val = self.name_raw
                 else:
-                    ret_val = ret_val.decode('utf-8')
+                    ret_val = ret_val.decode('utf-8', 'replace')
 
             elif name == "name_raw":
@@ -370,5 +373,5 @@
         try:
             if hasattr(fh, 'fileno'):
-                self.file = regfi.regfi_alloc(fh.fileno())
+                self.file = regfi.regfi_alloc(fh.fileno(), REGFI_ENCODING_UTF8)
                 return
         except:
@@ -379,5 +382,5 @@
         self.raw_file.seek = seek_cb_type(self.raw_file.cb_seek)
         self.raw_file.read = read_cb_type(self.raw_file.cb_read)
-        self.file = regfi.regfi_alloc_cb(self.raw_file)
+        self.file = regfi.regfi_alloc_cb(self.raw_file, REGFI_ENCODING_UTF8)
 
     def __getattr__(self, name):
@@ -387,6 +390,5 @@
         regfi.regfi_free(self.file)
         if self.raw_file != None:
-            regfi.regfi_free(self.file)
-            
+            self.raw_file = None
 
     def __iter__(self):
@@ -421,6 +423,5 @@
 
     def __init__(self, hive):
-        # REGFI_ENCODING_UTF8==1
-        self.iter = regfi.regfi_iterator_new(hive.file, 1)
+        self.iter = regfi.regfi_iterator_new(hive.file, REGFI_ENCODING_UTF8)
         if self.iter == None:
             raise Exception("Could not create iterator.  Current log:\n"
@@ -432,5 +433,5 @@
 
     def __del__(self):    
-        regfi.regfi_iterator_free(self.iter)        
+        regfi.regfi_iterator_free(self.iter)
 
     def __iter__(self):
@@ -440,5 +441,5 @@
     def __next__(self):
         if self.iteration_root == None:
-            self.iteration_root = self.current_key()            
+            self.iteration_root = self.current_key()
         elif not regfi.regfi_iterator_down(self.iter):
             up_ret = regfi.regfi_iterator_up(self.iter)
Index: trunk/python/pyregfi/structures.py
===================================================================
--- trunk/python/pyregfi/structures.py	(revision 212)
+++ trunk/python/pyregfi/structures.py	(revision 213)
@@ -10,4 +10,6 @@
 # XXX: can we always be sure enums are this size?
 REGFI_ENCODING = c_uint32
+REGFI_ENCODING_UTF8 = 1
+
 REGFI_DATA_TYPE = c_uint32
 
