diff -b -u -r --unidirectional-new-file xerces-c-src1_5_1/src/dom/DOM_DOMImplementation.cpp xerces-c/src/dom/DOM_DOMImplementation.cpp
--- xerces-c-src1_5_1/src/dom/DOM_DOMImplementation.cpp	Wed Jul 18 10:15:42 2001
+++ xerces-c/src/dom/DOM_DOMImplementation.cpp	Thu Sep 27 19:32:11 2001
@@ -121,14 +121,15 @@
 #include "DocumentImpl.hpp"
 #include "DocumentTypeImpl.hpp"
 #include "DStringPool.hpp"
-#include <util/XMLDeleterFor.hpp>
 #include <util/PlatformUtils.hpp>
+#include <util/XMLRegisterCleanup.hpp>
 
 //
 //  Static constants.  These are lazily initialized on first usage.
 //                     (Static constructors can not be safely used because
 //                      of order of initialization dependencies.)
 
+
 static DOM_DOMImplementation    *gDomimp;   // Points to the singleton instance
                                             //  of DOMImplementation that is returned
                                             //  by any call to getImplementation().
@@ -167,6 +168,13 @@
     return *this;
 };
 
+// -----------------------------------------------------------------------
+//  Reset the singleton DOM_DOMImplementation
+// -----------------------------------------------------------------------
+static void reinitImplementation() {
+	delete gDomimp;
+	gDomimp = 0;
+}
 
 //  getImplementation()  - Always returns the same singleton instance, which
 //                         is lazily created on the first call.  Note that
@@ -177,6 +185,8 @@
 //                         used concurrently by different threads.
 //
 DOM_DOMImplementation &DOM_DOMImplementation::getImplementation() {
+	static XMLRegisterCleanup implementationCleanup;
+
     if (gDomimp == 0)
     {
         DOM_DOMImplementation *t = new DOM_DOMImplementation;
@@ -186,17 +196,12 @@
         }
         else
         {
-            
-            XMLPlatformUtils::registerLazyData
-                (
-                new XMLDeleterFor<DOM_DOMImplementation>(gDomimp)
-                );
+			implementationCleanup.registerCleanup(reinitImplementation);
         }
         
     }
     return *gDomimp;
 };
-
 
 bool  DOM_DOMImplementation::hasFeature(const DOMString &feature,  const DOMString &version) 
 {
diff -b -u -r --unidirectional-new-file xerces-c-src1_5_1/src/idom/IDDOMImplementation.cpp xerces-c/src/idom/IDDOMImplementation.cpp
--- xerces-c-src1_5_1/src/idom/IDDOMImplementation.cpp	Wed Jul 18 10:15:46 2001
+++ xerces-c/src/idom/IDDOMImplementation.cpp	Thu Sep 27 19:32:19 2001
@@ -73,15 +73,16 @@
 #include "IDOM_DOMException.hpp"
 #include "IDDocumentImpl.hpp"
 #include "IDDocumentTypeImpl.hpp"
-#include <util/XMLDeleterFor.hpp>
 #include <util/PlatformUtils.hpp>
 #include <util/XMLUniDefs.hpp>
+#include <util/XMLRegisterCleanup.hpp>
 
 //
 //  Static constants.  These are lazily initialized on first usage.
 //                     (Static constructors can not be safely used because
 //                      of order of initialization dependencies.)
 
+
 static IDDOMImplementation    *gDomimp;   // Points to the singleton instance
                                             //  of DOMImplementation that is returnedreturned
                                             //  by any call to getImplementation().
@@ -121,6 +122,15 @@
 };
 
 
+// -----------------------------------------------------------------------
+//  Reset the singleton IDDOMImplementation
+// -----------------------------------------------------------------------
+static void reinitImplementation()
+{
+	delete gDomimp;
+	gDomimp = 0;
+}
+
 //  getImplementation()  - Always returns the same singleton instance, which
 //                         is lazily created on the first call.  Note that
 //                         DOM_Implementation must be thread-safe because
@@ -130,6 +140,8 @@
 //                         used concurrently by different threads.
 //
 IDOM_DOMImplementation *IDDOMImplementation::getImplementation() {
+	static XMLRegisterCleanup implementationCleanup;
+
     if (gDomimp == 0)
     {
         IDDOMImplementation *t = new IDDOMImplementation;
@@ -139,11 +151,7 @@
         }
         else
         {
-
-            XMLPlatformUtils::registerLazyData
-                (
-                new XMLDeleterFor<IDDOMImplementation>(gDomimp)
-                );
+			implementationCleanup.registerCleanup(reinitImplementation);
         }
 
     }
diff -b -u -r --unidirectional-new-file xerces-c-src1_5_1/src/internal/XMLScanner.cpp xerces-c/src/internal/XMLScanner.cpp
--- xerces-c-src1_5_1/src/internal/XMLScanner.cpp	Wed Jul 18 10:15:48 2001
+++ xerces-c/src/internal/XMLScanner.cpp	Thu Sep 27 19:21:19 2001
@@ -68,8 +68,8 @@
 #include <util/RefVectorOf.hpp>
 #include <util/RuntimeException.hpp>
 #include <util/UnexpectedEOFException.hpp>
-#include <util/XMLDeleterFor.hpp>
 #include <util/XMLMsgLoader.hpp>
+#include <util/XMLRegisterCleanup.hpp>
 #include <util/XMLUniDefs.hpp>
 #include <util/XMLUni.hpp>
 #include <util/XMLURL.hpp>
@@ -96,6 +96,8 @@
 // ---------------------------------------------------------------------------
 static XMLUInt32       gScannerId;
 static XMLMsgLoader*   gMsgLoader;
+static bool            sRegistered = false;
+static XMLMutex*       sScannerMutex = 0;
 
 // ---------------------------------------------------------------------------
 //  Local const data
@@ -114,37 +116,52 @@
 //  Local, static functions
 // ---------------------------------------------------------------------------
 
+// -----------------------------------------------------------------------
+//  Cleanup for the message loader
+// -----------------------------------------------------------------------
+static void reinitMsgLoader()
+{
+	delete gMsgLoader;
+	gMsgLoader = 0;
+}
+
+// -----------------------------------------------------------------------
+//  Cleanup for the scanner mutex
+// -----------------------------------------------------------------------
+static void reinitScannerMutex()
+{
+    delete sScannerMutex;
+    sScannerMutex = 0;
+    sRegistered = false;
+}
+
 //
 //  We need to fault in this mutex. But, since its used for synchronization
 //  itself, we have to do this the low level way using a compare and swap.
 //
 static XMLMutex& gScannerMutex()
 {
-    static bool      registered = false;
-    static XMLMutex* scannerMutex = 0;
-    if (!scannerMutex)
+    static XMLRegisterCleanup scannerMutexCleanup;
+    if (!sScannerMutex)
     {
         XMLMutex* tmpMutex = new XMLMutex;
-        if (XMLPlatformUtils::compareAndSwap((void**)&scannerMutex, tmpMutex, 0))
+        if (XMLPlatformUtils::compareAndSwap((void**)&sScannerMutex, tmpMutex, 0))
         {
             // Someone beat us to it, so let's clean up ours
             delete tmpMutex;
         }
 
         // Now lock it and try to register it
-        XMLMutexLock lock(scannerMutex);
+        XMLMutexLock lock(sScannerMutex);
 
         // If we got here first, then register it and set the registered flag
-        if (!registered)
+        if (!sRegistered)
         {
-            XMLPlatformUtils::registerLazyData
-            (
-                new XMLDeleterFor<XMLMutex>(scannerMutex)
-            );
-            registered = true;
+			scannerMutexCleanup.registerCleanup(reinitScannerMutex);
+            sRegistered = true;
         }
     }
-    return *scannerMutex;
+    return *sScannerMutex;
 }
 
 
@@ -831,6 +848,8 @@
 //
 void XMLScanner::commonInit()
 {
+	static XMLRegisterCleanup cleanupMsgLoader;
+
     //
     //  We have to do a little init that involves statics, so we have to
     //  use the mutex to protect it.
@@ -846,10 +865,7 @@
                 XMLPlatformUtils::panic(XMLPlatformUtils::Panic_CantLoadMsgDomain);
 
             // Register this object to be cleaned up at termination
-            XMLPlatformUtils::registerLazyData
-            (
-                new XMLDeleterFor<XMLMsgLoader>(gMsgLoader)
-            );
+			cleanupMsgLoader.registerCleanup(reinitMsgLoader);
         }
 
         // And assign ourselves the next available scanner id
diff -b -u -r --unidirectional-new-file xerces-c-src1_5_1/src/util/PlatformUtils.cpp xerces-c/src/util/PlatformUtils.cpp
--- xerces-c-src1_5_1/src/util/PlatformUtils.cpp	Wed Jul 18 10:15:54 2001
+++ xerces-c/src/util/PlatformUtils.cpp	Thu Sep 27 19:44:15 2001
@@ -127,6 +127,7 @@
 #include <util/XMLUni.hpp>
 #include <internal/XMLReader.hpp>
 #include <util/RuntimeException.hpp>
+#include <util/XMLRegisterCleanup.hpp>
 
 
 // ---------------------------------------------------------------------------
@@ -140,6 +141,21 @@
 static RefVectorOf<XMLDeleter>* gLazyData;
 static short                    gInitFlag = 0;
 
+// ---------------------------------------------------------------------------
+//  Global data
+//
+//	gXMLCleanupList
+//		This is a list of cleanup functions to be called on 
+//		XMLPlatformUtils::Terminate.  Their function is to reset static
+//		data in classes that use it.
+//
+//	gXMLCleanupListMutex
+//		This is a mutex that will be used to synchronise access to the global
+//		static data cleanup list
+// ---------------------------------------------------------------------------
+XMLRegisterCleanup*	gXMLCleanupList = 0;
+XMLMutex*			gXMLCleanupListMutex = 0;
+
 
 // ---------------------------------------------------------------------------
 //  XMLPlatformUtils: Static Data Members
@@ -176,6 +192,9 @@
     // Create the local sync mutex
     gSyncMutex = new XMLMutex;
 
+	// Create the mutex for the static data cleanup list
+	gXMLCleanupListMutex = new XMLMutex;
+
     // Create the array for saving lazily allocated objects to be deleted at termination
     gLazyData= new RefVectorOf<XMLDeleter>(512);
 
@@ -251,6 +270,17 @@
     delete gSyncMutex;
     gSyncMutex = 0;
 
+	// Clean up statically allocated, lazily cleaned data in each class
+	// that has registered for it.
+	// Note that calling doCleanup() also unregisters the cleanup
+	// function, so that we are chewing the list down to nothing here
+	while (gXMLCleanupList)
+		gXMLCleanupList->doCleanup();
+
+	// Clean up the mutex for accessing gXMLCleanupList
+	delete gXMLCleanupListMutex;
+	gXMLCleanupListMutex = 0;
+
     //
     //  And do platform termination. This cannot do use any XML services
     //  at all, it can only clean up local stuff. It it reports an error,
@@ -259,7 +289,7 @@
     platformTerm();
 
     // And say we are no longer initialized
-    gInitFlag = false;
+    gInitFlag = 0;
 }
 
 
diff -b -u -r --unidirectional-new-file xerces-c-src1_5_1/src/util/Platforms/HPUX/HPPlatformUtils.cpp xerces-c/src/util/Platforms/HPUX/HPPlatformUtils.cpp
--- xerces-c-src1_5_1/src/util/Platforms/HPUX/HPPlatformUtils.cpp	Wed Jul 18 10:15:52 2001
+++ xerces-c/src/util/Platforms/HPUX/HPPlatformUtils.cpp	Thu Sep 27 13:15:08 2001
@@ -748,6 +748,8 @@
 
 void XMLPlatformUtils::platformTerm()
 {
-    // We don't have any termination requirements at this time
+    // delete the mutex we created
+	closeMutex(atomicOpsMutex.fHandle);
+	atomicOpsMutex.fHandle = 0;
 }
 
diff -b -u -r --unidirectional-new-file xerces-c-src1_5_1/src/util/Platforms/IRIX/IRIXPlatformUtils.cpp xerces-c/src/util/Platforms/IRIX/IRIXPlatformUtils.cpp
--- xerces-c-src1_5_1/src/util/Platforms/IRIX/IRIXPlatformUtils.cpp	Wed Jul 18 10:15:52 2001
+++ xerces-c/src/util/Platforms/IRIX/IRIXPlatformUtils.cpp	Thu Sep 27 13:15:03 2001
@@ -689,6 +689,8 @@
 
 void XMLPlatformUtils::platformTerm()
 {
-    // We don't have any termination requirements at this time
+    // delete the mutex we created
+	closeMutex(atomicOpsMutex.fHandle);
+	atomicOpsMutex.fHandle = 0;
 }
 
diff -b -u -r --unidirectional-new-file xerces-c-src1_5_1/src/util/Platforms/Linux/LinuxPlatformUtils.cpp xerces-c/src/util/Platforms/Linux/LinuxPlatformUtils.cpp
--- xerces-c-src1_5_1/src/util/Platforms/Linux/LinuxPlatformUtils.cpp	Wed Jul 18 10:15:52 2001
+++ xerces-c/src/util/Platforms/Linux/LinuxPlatformUtils.cpp	Thu Sep 27 13:14:52 2001
@@ -731,6 +731,8 @@
 
 void XMLPlatformUtils::platformTerm()
 {
-    // We don't have any termination requirements at this time
+    // delete the mutex we created
+	closeMutex(atomicOpsMutex.fHandle);
+	atomicOpsMutex.fHandle = 0;
 }
 
diff -b -u -r --unidirectional-new-file xerces-c-src1_5_1/src/util/Platforms/OS400/OS400PlatformUtils.cpp xerces-c/src/util/Platforms/OS400/OS400PlatformUtils.cpp
--- xerces-c-src1_5_1/src/util/Platforms/OS400/OS400PlatformUtils.cpp	Wed Jul 18 10:15:54 2001
+++ xerces-c/src/util/Platforms/OS400/OS400PlatformUtils.cpp	Thu Sep 27 19:56:47 2001
@@ -82,10 +82,11 @@
 
 #if defined (XML_USE_ICONV400_TRANSCODER)
     #include <util/Transcoders/Iconv400/Iconv400TransService.hpp>
+	extern "C" void cleanupDefaultConverter();
 #elif defined (XML_USE_ICU_TRANSCODER)
     #include <util/Transcoders/ICU/ICUTransService.hpp>
 #else
- Transcoder not Specified - FOr OS/400 must be either ICU or Iconv400
+ Transcoder not Specified - For OS/400 must be either ICU or Iconv400 
 #endif
 
 #if defined(XML_USE_MSGFILE_MESSAGELOADER)
@@ -159,8 +160,12 @@
 
     gAtomicOpMutex = new pthread_mutex_t;	
 
-    if (pthread_mutex_init(gAtomicOpMutex, NULL))
+    if (pthread_mutex_init(gAtomicOpMutex, NULL)) {
+		delete gAtomicOpMutex;
+		gAtomicOpMutex = 0;
+
         panic( XMLPlatformUtils::Panic_SystemInit );
+	}
 }
 //
 //  This method is called very early in the bootstrapping process. This guy
@@ -756,6 +761,7 @@
     return tmp;
 }
 
+
 #else // #if !defined (APP_NO_THREADS)
 
 void XMLPlatformUtils::closeMutex(void* const mtxHandle)
@@ -816,6 +822,11 @@
 
 void XMLPlatformUtils::platformTerm()
 {
-    // We don't have any termination requirements at this time
-}
+	pthread_mutex_destroy(gAtomicOpMutex);
+    delete gAtomicOpMutex;
+	gAtomicOpMutex = 0;
 
+#if defined (XML_USE_ICONV400_TRANSCODER)
+	cleanupDefaultConverter();
+#endif
+}
diff -b -u -r --unidirectional-new-file xerces-c-src1_5_1/src/util/Platforms/Solaris/SolarisPlatformUtils.cpp xerces-c/src/util/Platforms/Solaris/SolarisPlatformUtils.cpp
--- xerces-c-src1_5_1/src/util/Platforms/Solaris/SolarisPlatformUtils.cpp	Wed Jul 18 10:15:54 2001
+++ xerces-c/src/util/Platforms/Solaris/SolarisPlatformUtils.cpp	Thu Sep 27 18:52:58 2001
@@ -111,6 +111,7 @@
 
 
 
+
 // ---------------------------------------------------------------------------
 //  Local Methods
 // ---------------------------------------------------------------------------
@@ -525,11 +526,17 @@
     gAtomicOpMutex = new pthread_mutex_t;   
 
 #if defined(XML_USE_DCE)
-    if (pthread_mutex_init(gAtomicOpMutex, pthread_mutexattr_default))
+    if (pthread_mutex_init(gAtomicOpMutex, pthread_mutexattr_default)) {
+	delete gAtomicOpMutex;
+	gAtomicOpMutex = 0;
         panic( XMLPlatformUtils::Panic_SystemInit );
+    }
 #else // XML_USE_DCE
-    if (pthread_mutex_init(gAtomicOpMutex, NULL))
+    if (pthread_mutex_init(gAtomicOpMutex, NULL)) {
+	delete gAtomicOpMutex;
+	gAtomicOpMutex = 0;
         panic( XMLPlatformUtils::Panic_SystemInit );
+    }
 #endif // XML_USE_DCE
 }
 
@@ -754,6 +761,8 @@
 
 void XMLPlatformUtils::platformTerm()
 {
-    // We don't have any termination requirements at this time
+	pthread_mutex_destroy(gAtomicOpMutex);
+    delete gAtomicOpMutex;
+	gAtomicOpMutex = 0;
 }
 
diff -b -u -r --unidirectional-new-file xerces-c-src1_5_1/src/util/Platforms/Tru64/Tru64PlatformUtils.cpp xerces-c/src/util/Platforms/Tru64/Tru64PlatformUtils.cpp
--- xerces-c-src1_5_1/src/util/Platforms/Tru64/Tru64PlatformUtils.cpp	Wed Jul 18 10:15:54 2001
+++ xerces-c/src/util/Platforms/Tru64/Tru64PlatformUtils.cpp	Thu Sep 27 13:17:29 2001
@@ -162,8 +162,11 @@
 
   gAtomicOpMutex = new pthread_mutex_t;	
 
-  if (pthread_mutex_init(gAtomicOpMutex, NULL))
+  if (pthread_mutex_init(gAtomicOpMutex, NULL)) {
+	delete gAtomicOpMutex;
+	gAtomicOpMutex = 0;
     panic( XMLPlatformUtils::Panic_SystemInit );
+  }
 }
 
 
@@ -690,5 +693,7 @@
 
 void XMLPlatformUtils::platformTerm()
 {
-    // We don't have any termination requirements at this time
+	pthread_mutex_destroy(gAtomicOpMutex);
+	delete gAtomicOpMutex;
+	gAtomicOpMutex = 0;
 }
diff -b -u -r --unidirectional-new-file xerces-c-src1_5_1/src/util/Platforms/UnixWare/UnixWarePlatformUtils.cpp xerces-c/src/util/Platforms/UnixWare/UnixWarePlatformUtils.cpp
--- xerces-c-src1_5_1/src/util/Platforms/UnixWare/UnixWarePlatformUtils.cpp	Wed Jul 18 10:15:54 2001
+++ xerces-c/src/util/Platforms/UnixWare/UnixWarePlatformUtils.cpp	Thu Sep 27 13:14:28 2001
@@ -727,6 +727,8 @@
 
 void XMLPlatformUtils::platformTerm()
 {
-    // We don't have any termination requirements at this time
+    // delete the mutex we created
+	closeMutex(atomicOpsMutex.fHandle);
+	atomicOpsMutex.fHandle = 0;
 }
 
diff -b -u -r --unidirectional-new-file xerces-c-src1_5_1/src/util/Transcoders/Iconv400/iconv_util.cpp xerces-c/src/util/Transcoders/Iconv400/iconv_util.cpp
--- xerces-c-src1_5_1/src/util/Transcoders/Iconv400/iconv_util.cpp	Wed Jul 18 10:15:56 2001
+++ xerces-c/src/util/Transcoders/Iconv400/iconv_util.cpp	Thu Sep 27 19:08:59 2001
@@ -84,6 +84,18 @@
 #define defaultConverter (_defaultConverter==NULL)?_defaultConverter=ucnv_open(NULL, &gErr):_defaultConverter
 
 
+/* Cleans up the default converter if it has been allocated.
+   This is a little messy, but I know the code well enough to
+   do anything neater.
+ */
+void cleanupDefaultConverter()
+{
+	if (_defaultConverter != NULL) {
+		ucnv_close(_defaultConverter);
+		_defaultConverter = NULL;
+	}
+}
+
 static char DEFAULT_CONVERTER_NAME[60] = "";
 const char* iconv_getDefaultCodepage()
 {
diff -b -u -r --unidirectional-new-file xerces-c-src1_5_1/src/util/XMLException.cpp xerces-c/src/util/XMLException.cpp
--- xerces-c-src1_5_1/src/util/XMLException.cpp	Wed Jul 18 10:15:58 2001
+++ xerces-c/src/util/XMLException.cpp	Thu Sep 27 19:33:40 2001
@@ -64,9 +64,9 @@
 // ---------------------------------------------------------------------------
 #include <util/Mutexes.hpp>
 #include <util/PlatformUtils.hpp>
-#include <util/XMLDeleterFor.hpp>
 #include <util/XMLException.hpp>
 #include <util/XMLMsgLoader.hpp>
+#include <util/XMLRegisterCleanup.hpp>
 #include <util/XMLString.hpp>
 #include <util/XMLUniDefs.hpp>
 #include <util/XMLUni.hpp>
@@ -90,35 +90,47 @@
 
 
 // ---------------------------------------------------------------------------
+//  Local, static data
+// ---------------------------------------------------------------------------
+static XMLMsgLoader* sLoader = 0;
+static XMLMutex* sMsgMutex = 0;
+
+// ---------------------------------------------------------------------------
 //  Local, static functions
 // ---------------------------------------------------------------------------
 
+// -----------------------------------------------------------------------
+//  Reinitialise the message mutex
+// -----------------------------------------------------------------------
+static void reinitMsgMutex()
+{
+	delete sMsgMutex;
+	sMsgMutex = 0;
+}
+
 //
 //  We need to fault in this mutex. But, since its used for synchronization
 //  itself, we have to do this the low level way using a compare and swap.
 //
 static XMLMutex& gMsgMutex()
 {
-    static XMLMutex* msgMutex = 0;
-    if (!msgMutex)
+	static XMLRegisterCleanup msgMutexCleanup;
+    if (!sMsgMutex)
     {
         XMLMutex* tmpMutex = new XMLMutex;
-        if (XMLPlatformUtils::compareAndSwap((void**)&msgMutex, tmpMutex, 0))
+        if (XMLPlatformUtils::compareAndSwap((void**)&sMsgMutex, tmpMutex, 0))
         {
             // Some other thread beat us to it, so let's clean up ours.
             delete tmpMutex;
         }
         else
         {
-            // This is the real mutex.  Register it for deletion at Termination.
-            XMLPlatformUtils::registerLazyData
-                (
-                new XMLDeleterFor<XMLMutex>(msgMutex)
-                );
+            // This is the real mutex.  Register it for cleanup at Termination.
+			msgMutexCleanup.registerCleanup(reinitMsgMutex);
         }
         
     }
-    return *msgMutex;
+    return *sMsgMutex;
 }
 
 
@@ -127,6 +139,15 @@
 //  Local methods
 // ---------------------------------------------------------------------------
 
+// -----------------------------------------------------------------------
+//  Reinitialise the message loader
+// -----------------------------------------------------------------------
+static void reinitMsgLoader()
+{
+	delete sLoader;
+	sLoader = 0;
+}
+
 //
 //  This method is a lazy evaluator for the message loader for exception
 //  messages.
@@ -136,29 +157,24 @@
 //
 static XMLMsgLoader& gGetMsgLoader()
 {
+	static XMLRegisterCleanup msgLoaderCleanup;
+
     // Fault it in on first request
-    static XMLMsgLoader* gLoader = 0;
-    if (!gLoader)
+    if (!sLoader)
     {
-        gLoader = XMLPlatformUtils::loadMsgSet(XMLUni::fgExceptDomain);
-        if (!gLoader)
+        sLoader = XMLPlatformUtils::loadMsgSet(XMLUni::fgExceptDomain);
+        if (!sLoader)
             XMLPlatformUtils::panic(XMLPlatformUtils::Panic_CantLoadMsgDomain);
 
         //
-        // Register this XMLMsgLoader for deletion at Termination.
+        // Register this XMLMsgLoader for cleanup at Termination.
         //
-        XMLPlatformUtils::registerLazyData
-            (
-            new XMLDeleterFor<XMLMsgLoader>(gLoader)
-            );
-        
+        msgLoaderCleanup.registerCleanup(reinitMsgLoader);
     }
     
     // We got it, so return it
-    return *gLoader;
+    return *sLoader;
 }
-
-
 
 // ---------------------------------------------------------------------------
 //  XMLException: Virtual destructor
diff -b -u -r --unidirectional-new-file xerces-c-src1_5_1/src/util/XMLRegisterCleanup.hpp xerces-c/src/util/XMLRegisterCleanup.hpp
--- xerces-c-src1_5_1/src/util/XMLRegisterCleanup.hpp	Thu Jan  1 00:00:00 1970
+++ xerces-c/src/util/XMLRegisterCleanup.hpp	Thu Sep 27 15:42:34 2001
@@ -0,0 +1,162 @@
+/*
+ * The Apache Software License, Version 1.1
+ * 
+ * Copyright (c) 1999-2000 The Apache Software Foundation.  All rights
+ * reserved.
+ * 
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer. 
+ * 
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in
+ *    the documentation and/or other materials provided with the
+ *    distribution.
+ * 
+ * 3. The end-user documentation included with the redistribution,
+ *    if any, must include the following acknowledgment:  
+ *       "This product includes software developed by the
+ *        Apache Software Foundation (http://www.apache.org/)."
+ *    Alternately, this acknowledgment may appear in the software itself,
+ *    if and wherever such third-party acknowledgments normally appear.
+ * 
+ * 4. The names "Xerces" and "Apache Software Foundation" must
+ *    not be used to endorse or promote products derived from this
+ *    software without prior written permission. For written 
+ *    permission, please contact apache\@apache.org.
+ * 
+ * 5. Products derived from this software may not be called "Apache",
+ *    nor may "Apache" appear in their name, without prior written
+ *    permission of the Apache Software Foundation.
+ * 
+ * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
+ * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED.  IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
+ * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
+ * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
+ * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
+ * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
+ * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ * ====================================================================
+ * 
+ * This software consists of voluntary contributions made by many
+ * individuals on behalf of the Apache Software Foundation, and was
+ * originally based on software copyright (c) 1999, International
+ * Business Machines, Inc., http://www.ibm.com .  For more information
+ * on the Apache Software Foundation, please see
+ * <http://www.apache.org/>.
+ */
+
+#if !defined(XMLREGISTERCLEANUP_HPP)
+#define XMLREGISTERCLEANUP_HPP
+
+#include <util/Mutexes.hpp>
+
+// This is a mutex for exclusive use by this class
+extern XMLMutex* gXMLCleanupListMutex;
+
+// This is the head of a list of XMLRegisterCleanup objects that
+// is used during XMLPlatformUtils::Terminate() to find objects to
+// clean up
+class XMLRegisterCleanup;
+extern XMLRegisterCleanup* gXMLCleanupList;
+
+// 
+//  For internal use only.
+//
+//  This class is used by the platform utilities class to support 
+//  reinitialisation of global/static data which is lazily created. 
+//  Since that data is widely spread out the platform utilities
+//  class cannot know about them directly. So, the code that creates such
+//  objects creates an registers a cleanup for the object. The platform
+//  termination call will iterate the list and delete the objects.
+//
+//  N.B. These objects need to be statically allocated.  I couldn't think
+//  of a neat way of ensuring this - can anyone else?
+
+class XMLRegisterCleanup
+{
+public :
+	// The cleanup function to be called on XMLPlatformUtils::Terminate()
+	typedef void (*XMLCleanupFn)();
+	
+	void doCleanup() {
+		// When performing cleanup, we only do this once, but we can
+		// cope if somehow we have been called twice.
+		if (m_cleanupFn) {
+			m_cleanupFn();
+			unregisterCleanup();
+		}
+	}
+
+	// This function is called during initialisation of static data to
+	// register a function to be called on XMLPlatformUtils::Terminate.
+	// It gives an object that uses static data an opportunity to reset
+	// such data.
+	void registerCleanup(XMLCleanupFn cleanupFn) {
+		// Store the cleanup function
+		m_cleanupFn = cleanupFn;
+		
+		// Add this object to the list head, if it is not already 
+		// present - which it shouldn't be.
+		// This is done under a mutex to ensure thread safety.
+		gXMLCleanupListMutex->lock();
+		if (!m_nextCleanup && !m_prevCleanup) {
+			m_nextCleanup = gXMLCleanupList;
+			gXMLCleanupList = this;
+
+			if (m_nextCleanup) 
+				m_nextCleanup->m_prevCleanup = this;
+		}
+		gXMLCleanupListMutex->unlock();
+	}
+
+	// This function can be called either from XMLPlatformUtils::Terminate
+	// to state that the cleanup has been performed and should not be
+	// performed again, or from code that you have written that determines
+	// that cleanup is no longer necessary.
+	void unregisterCleanup() {
+		gXMLCleanupListMutex->lock();
+
+		// Unlink this object from the cleanup list
+		if (m_nextCleanup) m_nextCleanup->m_prevCleanup = m_prevCleanup;
+		
+		if (!m_prevCleanup) gXMLCleanupList = m_nextCleanup;
+		else m_prevCleanup->m_nextCleanup = m_nextCleanup;
+
+		gXMLCleanupListMutex->unlock();
+		
+		// Reset the object to the default state
+		resetCleanup();
+	}
+
+	// The default constructor sets a state that ensures that this object
+	// will do nothing
+	XMLRegisterCleanup()
+	{
+		resetCleanup();
+	}
+
+private:
+	// This is the cleanup function to be called
+	XMLCleanupFn m_cleanupFn;
+
+	// These are list pointers to the next/prev cleanup function to be called
+	XMLRegisterCleanup *m_nextCleanup, *m_prevCleanup;
+
+	// This function reinitialises the object to the default state
+	void resetCleanup() {
+		m_nextCleanup = 0;
+		m_prevCleanup = 0;
+		m_cleanupFn = 0;
+	}
+};
+
+#endif
diff -b -u -r --unidirectional-new-file xerces-c-src1_5_1/src/util/regx/RangeTokenMap.cpp xerces-c/src/util/regx/RangeTokenMap.cpp
--- xerces-c-src1_5_1/src/util/regx/RangeTokenMap.cpp	Wed Jul 18 10:15:56 2001
+++ xerces-c/src/util/regx/RangeTokenMap.cpp	Thu Sep 27 19:33:58 2001
@@ -88,8 +88,8 @@
 #include <util/regx/TokenFactory.hpp>
 #include <util/regx/RangeFactory.hpp>
 #include <util/PlatformUtils.hpp>
-#include <util/XMLDeleterFor.hpp>
 #include <util/XMLExceptMsgs.hpp>
+#include <util/XMLRegisterCleanup.hpp>
 
 // ---------------------------------------------------------------------------
 //  Static member data initialization
@@ -268,17 +268,23 @@
 //  RangeTokenMap: Instance methods
 // ---------------------------------------------------------------------------
 RangeTokenMap* RangeTokenMap::instance() {
+	static XMLRegisterCleanup instanceCleanup;
 
 	if (!fInstance) {
 
 		fInstance = new RangeTokenMap();
-        XMLPlatformUtils::registerLazyData
-        (
-            new XMLDeleterFor<RangeTokenMap>(fInstance)
-        );
+		instanceCleanup.registerCleanup(reinitInstance);
 	}
 	
     return (fInstance);
+}
+
+// -----------------------------------------------------------------------
+//  Notification that lazy data has been deleted
+// -----------------------------------------------------------------------
+void RangeTokenMap::reinitInstance() {
+	delete fInstance;
+	fInstance = 0;
 }
 
 /**
diff -b -u -r --unidirectional-new-file xerces-c-src1_5_1/src/util/regx/RangeTokenMap.hpp xerces-c/src/util/regx/RangeTokenMap.hpp
--- xerces-c-src1_5_1/src/util/regx/RangeTokenMap.hpp	Wed Jul 18 10:15:56 2001
+++ xerces-c/src/util/regx/RangeTokenMap.hpp	Thu Sep 27 12:38:30 2001
@@ -140,6 +140,11 @@
     // -----------------------------------------------------------------------
 	TokenFactory* getTokenFactory() const;
 
+	// -----------------------------------------------------------------------
+    //  Notification that lazy data has been deleted
+    // -----------------------------------------------------------------------
+	static void reinitInstance();
+
 protected:
     // -----------------------------------------------------------------------
     //  Constructor and destructors
diff -b -u -r --unidirectional-new-file xerces-c-src1_5_1/src/validators/datatype/DatatypeValidatorFactory.cpp xerces-c/src/validators/datatype/DatatypeValidatorFactory.cpp
--- xerces-c-src1_5_1/src/validators/datatype/DatatypeValidatorFactory.cpp	Wed Jul 18 10:16:00 2001
+++ xerces-c/src/validators/datatype/DatatypeValidatorFactory.cpp	Thu Sep 27 19:21:36 2001
@@ -130,8 +130,7 @@
 #include <validators/datatype/ListDatatypeValidator.hpp>
 #include <validators/datatype/UnionDatatypeValidator.hpp>
 #include <util/PlatformUtils.hpp>
-#include <util/XMLDeleterFor.hpp>
-
+#include <util/XMLRegisterCleanup.hpp>
 
 // ---------------------------------------------------------------------------
 //  DatatypeValidatorFactory: Local const data
@@ -314,21 +313,29 @@
 }
 
 
+// -----------------------------------------------------------------------
+//  Notification that lazy data has been deleted
+// -----------------------------------------------------------------------
+void DatatypeValidatorFactory::reinitRegistry() {
+	delete fBuiltInRegistry;
+	fBuiltInRegistry = 0;
+	fRegistryExpanded = 0;
+}
+
 // ---------------------------------------------------------------------------
 //  DatatypeValidatorFactory: Registry initialization methods
 // ---------------------------------------------------------------------------
 void DatatypeValidatorFactory::initializeDTDRegistry()
 {
+	static XMLRegisterCleanup builtInRegistryCleanup;
+
 	if (fRegistryExpanded)
 		return;
 
     if (fBuiltInRegistry == 0) {
 
         fBuiltInRegistry = new RefHashTableOf<DatatypeValidator>(109);
-        XMLPlatformUtils::registerLazyData
-        (
-            new XMLDeleterFor<DVHashTable>(fBuiltInRegistry)
-        );
+		builtInRegistryCleanup.registerCleanup(reinitRegistry);
     }
 
 
diff -b -u -r --unidirectional-new-file xerces-c-src1_5_1/src/validators/datatype/DatatypeValidatorFactory.hpp xerces-c/src/validators/datatype/DatatypeValidatorFactory.hpp
--- xerces-c-src1_5_1/src/validators/datatype/DatatypeValidatorFactory.hpp	Wed Jul 18 10:16:00 2001
+++ xerces-c/src/validators/datatype/DatatypeValidatorFactory.hpp	Thu Sep 27 15:12:16 2001
@@ -219,6 +219,11 @@
       */
 	void resetRegistry();
 
+	// -----------------------------------------------------------------------
+    //  Notification that lazy data has been deleted
+    // -----------------------------------------------------------------------
+	static void reinitRegistry();
+
 private:
     // -----------------------------------------------------------------------
     //  CleanUp methods
diff -b -u -r --unidirectional-new-file xerces-c-src1_5_1/src/validators/schema/GeneralAttributeCheck.cpp xerces-c/src/validators/schema/GeneralAttributeCheck.cpp
--- xerces-c-src1_5_1/src/validators/schema/GeneralAttributeCheck.cpp	Wed Jul 18 10:16:00 2001
+++ xerces-c/src/validators/schema/GeneralAttributeCheck.cpp	Thu Sep 27 19:34:13 2001
@@ -83,7 +83,7 @@
 #include <framework/XMLErrorCodes.hpp>
 #include <validators/schema/TraverseSchema.hpp>
 #include <util/PlatformUtils.hpp>
-#include <util/XMLDeleterFor.hpp>
+#include <util/XMLRegisterCleanup.hpp>
 #include <validators/datatype/DatatypeValidatorFactory.hpp>
 
 // ---------------------------------------------------------------------------
@@ -713,17 +713,24 @@
 //  GeneralAttributeCheck: Instance methods
 // ---------------------------------------------------------------------------
 GeneralAttributeCheck* GeneralAttributeCheck::instance() {
+	static XMLRegisterCleanup instanceCleanup;
 
     if (!fInstance) {
 
         fInstance = new GeneralAttributeCheck();
-        XMLPlatformUtils::registerLazyData
-        (
-            new XMLDeleterFor<GeneralAttributeCheck>(fInstance)
-        );
+		instanceCleanup.registerCleanup(reinitInstance);
     }
 
     return fInstance;
+}
+
+// -----------------------------------------------------------------------
+//  Notification that lazy data has been deleted
+// -----------------------------------------------------------------------
+void 
+GeneralAttributeCheck::reinitInstance() {
+	delete fInstance;
+	fInstance = 0;
 }
 
 // ---------------------------------------------------------------------------
diff -b -u -r --unidirectional-new-file xerces-c-src1_5_1/src/validators/schema/GeneralAttributeCheck.hpp xerces-c/src/validators/schema/GeneralAttributeCheck.hpp
--- xerces-c-src1_5_1/src/validators/schema/GeneralAttributeCheck.hpp	Wed Jul 18 10:16:00 2001
+++ xerces-c/src/validators/schema/GeneralAttributeCheck.hpp	Thu Sep 27 15:12:43 2001
@@ -148,6 +148,11 @@
                          const unsigned short elemContext,
                          TraverseSchema* const schema);
 
+	// -----------------------------------------------------------------------
+    //  Notification that lazy data has been deleted
+    // -----------------------------------------------------------------------
+	static void reinitInstance();
+
 private:
     // -----------------------------------------------------------------------
     //  Constructor and destructors

