From 680f35dfe76878c3a9d1e63daa466a598753eef7 Mon Sep 17 00:00:00 2001
From: PeiYong Zhang <peiyongz@apache.org>
Date: Wed, 24 Oct 2001 18:07:52 +0000
Subject: [PATCH] [Bug#880] minor changes

git-svn-id: https://svn.apache.org/repos/asf/xerces/c/trunk@173156 13f79535-47bb-0310-9956-ffa450edef68
---
 src/util/XMLRegisterCleanup.hpp | 27 +++++++++++++++++++++------
 1 file changed, 21 insertions(+), 6 deletions(-)

diff --git a/src/util/XMLRegisterCleanup.hpp b/src/util/XMLRegisterCleanup.hpp
index 21eeaf113..3b56900dd 100644
--- a/src/util/XMLRegisterCleanup.hpp
+++ b/src/util/XMLRegisterCleanup.hpp
@@ -90,10 +90,12 @@ public :
 	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();
-		}
+		if (m_cleanupFn) 
+            m_cleanupFn();
+
+        // We need to remove "this" from the list
+        // irregardless of the cleanup Function
+        unregisterCleanup();
 	}
 
 	// This function is called during initialisation of static data to
@@ -125,7 +127,20 @@ public :
 	void unregisterCleanup() {
 		gXMLCleanupListMutex->lock();
 
-		// Unlink this object from the cleanup list
+        //
+        // To protect against some compiler's (eg hp11) optimization
+        // to change "this" as they update gXMLCleanupList
+        //
+        // refer to 
+        // void XMLPlatformUtils::Terminate()
+        //       ... 
+        //       while (gXMLCleanupList)
+		//            gXMLCleanupList->doCleanup();
+        //
+
+        XMLRegisterCleanup *tmpThis = (XMLRegisterCleanup*) this;
+
+        // Unlink this object from the cleanup list
 		if (m_nextCleanup) m_nextCleanup->m_prevCleanup = m_prevCleanup;
 		
 		if (!m_prevCleanup) gXMLCleanupList = m_nextCleanup;
@@ -134,7 +149,7 @@ public :
 		gXMLCleanupListMutex->unlock();
 		
 		// Reset the object to the default state
-		resetCleanup();
+		tmpThis->resetCleanup();
 	}
 
 	// The default constructor sets a state that ensures that this object
-- 
GitLab