Cleanup xref table at exit of program (not after check), or when new file
[gedcom-parse.git] / gedcom / xref.c
index ea3e1fa7ded85cc6cbb8f445175e313aa606d489..1aa3b6c21347685b6312ca271ac7e3f29a721103 100644 (file)
@@ -83,8 +83,20 @@ struct xref_node *make_xref_node()
   return xr;
 }
 
+void cleanup_xrefs()
+{
+  hash_free(xrefs);
+  xrefs = NULL;
+}
+
 void make_xref_table()
 {
+  if (xrefs)
+    cleanup_xrefs();
+  else
+    /* Only register initially (if xrefs is still NULL) */
+    /* So that it is only registered once */
+    atexit(cleanup_xrefs);
   xrefs = hash_create(HASHCOUNT_T_MAX, NULL, NULL);
   hash_set_allocator(xrefs, xref_alloc, xref_free, NULL);
 }
@@ -111,7 +123,6 @@ int check_xref_table()
     }
   }
   
-  hash_free(xrefs);
   return result;
 }