You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@xerces.apache.org by db...@apache.org on 2005/06/06 19:41:43 UTC

svn commit: r180348 [1/2] - in /xerces/c/trunk/src/xercesc: framework/ framework/psvi/ internal/ parsers/ util/ util/regx/ validators/datatype/ validators/schema/ validators/schema/identity/

Author: dbertoni
Date: Mon Jun  6 10:41:39 2005
New Revision: 180348

URL: http://svn.apache.org/viewcvs?rev=180348&view=rev
Log:
Fixes for Jira issue XERCESC-1368.

Modified:
    xerces/c/trunk/src/xercesc/framework/LocalFileFormatTarget.cpp
    xerces/c/trunk/src/xercesc/framework/XMLAttDef.cpp
    xerces/c/trunk/src/xercesc/framework/XMLAttr.cpp
    xerces/c/trunk/src/xercesc/framework/XMLEntityDecl.cpp
    xerces/c/trunk/src/xercesc/framework/XMLNotationDecl.cpp
    xerces/c/trunk/src/xercesc/framework/psvi/XSValue.cpp
    xerces/c/trunk/src/xercesc/internal/DGXMLScanner.cpp
    xerces/c/trunk/src/xercesc/internal/IGXMLScanner.cpp
    xerces/c/trunk/src/xercesc/internal/ReaderMgr.cpp
    xerces/c/trunk/src/xercesc/internal/SGXMLScanner.cpp
    xerces/c/trunk/src/xercesc/internal/WFXMLScanner.cpp
    xerces/c/trunk/src/xercesc/internal/XMLGrammarPoolImpl.cpp
    xerces/c/trunk/src/xercesc/internal/XMLGrammarPoolImpl.hpp
    xerces/c/trunk/src/xercesc/internal/XMLScanner.cpp
    xerces/c/trunk/src/xercesc/internal/XMLScanner.hpp
    xerces/c/trunk/src/xercesc/parsers/AbstractDOMParser.cpp
    xerces/c/trunk/src/xercesc/parsers/AbstractDOMParser.hpp
    xerces/c/trunk/src/xercesc/parsers/DOMBuilderImpl.cpp
    xerces/c/trunk/src/xercesc/parsers/DOMBuilderImpl.hpp
    xerces/c/trunk/src/xercesc/parsers/SAX2XMLReaderImpl.cpp
    xerces/c/trunk/src/xercesc/parsers/SAX2XMLReaderImpl.hpp
    xerces/c/trunk/src/xercesc/parsers/SAXParser.cpp
    xerces/c/trunk/src/xercesc/parsers/SAXParser.hpp
    xerces/c/trunk/src/xercesc/parsers/XercesDOMParser.cpp
    xerces/c/trunk/src/xercesc/parsers/XercesDOMParser.hpp
    xerces/c/trunk/src/xercesc/util/Janitor.c
    xerces/c/trunk/src/xercesc/util/Janitor.hpp
    xerces/c/trunk/src/xercesc/util/QName.cpp
    xerces/c/trunk/src/xercesc/util/XMLAbstractDoubleFloat.cpp
    xerces/c/trunk/src/xercesc/util/XMLBigDecimal.cpp
    xerces/c/trunk/src/xercesc/util/XMLBigInteger.cpp
    xerces/c/trunk/src/xercesc/util/XMLString.cpp
    xerces/c/trunk/src/xercesc/util/XMLStringTokenizer.cpp
    xerces/c/trunk/src/xercesc/util/XMLURL.cpp
    xerces/c/trunk/src/xercesc/util/XMLURL.hpp
    xerces/c/trunk/src/xercesc/util/XMLUri.cpp
    xerces/c/trunk/src/xercesc/util/regx/BMPattern.cpp
    xerces/c/trunk/src/xercesc/util/regx/RangeTokenMap.cpp
    xerces/c/trunk/src/xercesc/util/regx/RegularExpression.cpp
    xerces/c/trunk/src/xercesc/validators/datatype/AnyURIDatatypeValidator.cpp
    xerces/c/trunk/src/xercesc/validators/datatype/DateDatatypeValidator.cpp
    xerces/c/trunk/src/xercesc/validators/datatype/DateTimeDatatypeValidator.cpp
    xerces/c/trunk/src/xercesc/validators/datatype/DayDatatypeValidator.cpp
    xerces/c/trunk/src/xercesc/validators/datatype/DurationDatatypeValidator.cpp
    xerces/c/trunk/src/xercesc/validators/datatype/ListDatatypeValidator.cpp
    xerces/c/trunk/src/xercesc/validators/datatype/MonthDatatypeValidator.cpp
    xerces/c/trunk/src/xercesc/validators/datatype/MonthDayDatatypeValidator.cpp
    xerces/c/trunk/src/xercesc/validators/datatype/TimeDatatypeValidator.cpp
    xerces/c/trunk/src/xercesc/validators/datatype/UnionDatatypeValidator.cpp
    xerces/c/trunk/src/xercesc/validators/datatype/YearDatatypeValidator.cpp
    xerces/c/trunk/src/xercesc/validators/datatype/YearMonthDatatypeValidator.cpp
    xerces/c/trunk/src/xercesc/validators/schema/SchemaGrammar.cpp
    xerces/c/trunk/src/xercesc/validators/schema/TraverseSchema.cpp
    xerces/c/trunk/src/xercesc/validators/schema/identity/FieldValueMap.cpp
    xerces/c/trunk/src/xercesc/validators/schema/identity/FieldValueMap.hpp
    xerces/c/trunk/src/xercesc/validators/schema/identity/IdentityConstraint.cpp
    xerces/c/trunk/src/xercesc/validators/schema/identity/IdentityConstraintHandler.cpp
    xerces/c/trunk/src/xercesc/validators/schema/identity/ValueStoreCache.cpp
    xerces/c/trunk/src/xercesc/validators/schema/identity/XPathMatcher.cpp
    xerces/c/trunk/src/xercesc/validators/schema/identity/XPathMatcherStack.cpp
    xerces/c/trunk/src/xercesc/validators/schema/identity/XPathMatcherStack.hpp
    xerces/c/trunk/src/xercesc/validators/schema/identity/XercesXPath.cpp

Modified: xerces/c/trunk/src/xercesc/framework/LocalFileFormatTarget.cpp
URL: http://svn.apache.org/viewcvs/xerces/c/trunk/src/xercesc/framework/LocalFileFormatTarget.cpp?rev=180348&r1=180347&r2=180348&view=diff
==============================================================================
--- xerces/c/trunk/src/xercesc/framework/LocalFileFormatTarget.cpp (original)
+++ xerces/c/trunk/src/xercesc/framework/LocalFileFormatTarget.cpp Mon Jun  6 10:41:39 2005
@@ -61,6 +61,7 @@
 #include <xercesc/framework/MemoryManager.hpp>
 #include <xercesc/util/IOException.hpp>
 #include <xercesc/util/OutOfMemoryException.hpp>
+#include <assert.h>
 #include <string.h>
 
 XERCES_CPP_NAMESPACE_BEGIN
@@ -189,10 +190,8 @@
     {
         return false;
     }
-    catch (...)
-    {
-        return false;
-    }
+
+    assert(newBuf);
 
     // Copy over the old stuff
     memcpy(newBuf, fDataBuf, fCapacity * sizeof(XMLByte) + 4);

Modified: xerces/c/trunk/src/xercesc/framework/XMLAttDef.cpp
URL: http://svn.apache.org/viewcvs/xerces/c/trunk/src/xercesc/framework/XMLAttDef.cpp?rev=180348&r1=180347&r2=180348&view=diff
==============================================================================
--- xerces/c/trunk/src/xercesc/framework/XMLAttDef.cpp (original)
+++ xerces/c/trunk/src/xercesc/framework/XMLAttDef.cpp Mon Jun  6 10:41:39 2005
@@ -130,6 +130,8 @@
 {
 }
 
+typedef JanitorMemFunCall<XMLAttDef>    CleanupType;
+
 XMLAttDef::XMLAttDef( const XMLCh* const           attrValue
                     , const XMLAttDef::AttTypes    type
                     , const XMLAttDef::DefAttTypes defType
@@ -146,6 +148,8 @@
     , fEnumeration(0)
     , fMemoryManager(manager)
 {
+    CleanupType cleanup(this, &XMLAttDef::cleanUp);
+
     try
     {
         fValue = XMLString::replicate(attrValue, fMemoryManager);
@@ -153,12 +157,12 @@
     }
     catch(const OutOfMemoryException&)
     {
+        cleanup.release();
+
         throw;
     }
-    catch(...)
-    {
-        cleanUp();
-    }
+
+    cleanup.release();
 }
 
 

Modified: xerces/c/trunk/src/xercesc/framework/XMLAttr.cpp
URL: http://svn.apache.org/viewcvs/xerces/c/trunk/src/xercesc/framework/XMLAttr.cpp?rev=180348&r1=180347&r2=180348&view=diff
==============================================================================
--- xerces/c/trunk/src/xercesc/framework/XMLAttr.cpp (original)
+++ xerces/c/trunk/src/xercesc/framework/XMLAttr.cpp Mon Jun  6 10:41:39 2005
@@ -45,6 +45,8 @@
     fAttName = new (fMemoryManager) QName(fMemoryManager);
 }
 
+typedef JanitorMemFunCall<XMLAttr>  CleanupType;
+
 XMLAttr::XMLAttr(   const   unsigned int        uriId
                     , const XMLCh* const        attrName
                     , const XMLCh* const        attrPrefix
@@ -64,6 +66,8 @@
     , fDatatypeValidator(datatypeValidator)
     , fIsSchemaValidated(isSchema)
 {
+    CleanupType cleanup(this, &XMLAttr::cleanUp);
+
     try
     {
         //
@@ -75,12 +79,12 @@
     }
     catch(const OutOfMemoryException&)
     {
+        cleanup.release();
+
         throw;
     }
-    catch(...)
-    {
-        cleanUp();
-    }
+
+    cleanup.release();
 }
 
 XMLAttr::XMLAttr(   const   unsigned int        uriId
@@ -101,6 +105,8 @@
     , fDatatypeValidator(datatypeValidator)
     , fIsSchemaValidated(isSchema)
 {
+    CleanupType cleanup(this, &XMLAttr::cleanUp);
+
     try
     {
         //  Just call the local setters to set up everything. Too much
@@ -110,12 +116,12 @@
     }
     catch(const OutOfMemoryException&)
     {
+        cleanup.release();
+
         throw;
     }
-    catch(...)
-    {
-        cleanUp();
-    }
+
+    cleanup.release();
 }
 
 

Modified: xerces/c/trunk/src/xercesc/framework/XMLEntityDecl.cpp
URL: http://svn.apache.org/viewcvs/xerces/c/trunk/src/xercesc/framework/XMLEntityDecl.cpp?rev=180348&r1=180347&r2=180348&view=diff
==============================================================================
--- xerces/c/trunk/src/xercesc/framework/XMLEntityDecl.cpp (original)
+++ xerces/c/trunk/src/xercesc/framework/XMLEntityDecl.cpp Mon Jun  6 10:41:39 2005
@@ -61,6 +61,8 @@
     fName = XMLString::replicate(entName, fMemoryManager);
 }
 
+typedef JanitorMemFunCall<XMLEntityDecl>  CleanupType;
+
 XMLEntityDecl::XMLEntityDecl(const  XMLCh* const   entName
                             , const XMLCh* const   value
                             , MemoryManager* const manager) :
@@ -74,6 +76,8 @@
     , fBaseURI(0)
     , fMemoryManager(manager)
 {
+    CleanupType cleanup(this, &XMLEntityDecl::cleanUp);
+
     try
     {
         fValue = XMLString::replicate(value, fMemoryManager);
@@ -81,12 +85,12 @@
     }
     catch(const OutOfMemoryException&)
     {
+        cleanup.release();
+
         throw;
     }
-    catch(...)
-    {
-        cleanUp();
-    }
+
+    cleanup.release();
 }
 
 XMLEntityDecl::XMLEntityDecl(const  XMLCh* const   entName
@@ -102,6 +106,8 @@
     , fBaseURI(0)
     , fMemoryManager(manager)
 {
+    CleanupType cleanup(this, &XMLEntityDecl::cleanUp);
+
     try
     {
         XMLCh dummy[2] = { chNull, chNull };
@@ -111,12 +117,12 @@
     }
     catch(const OutOfMemoryException&)
     {
+        cleanup.release();
+
         throw;
     }
-    catch(...)
-    {
-        cleanUp();
-    }
+
+    cleanup.release();
 }
 
 XMLEntityDecl::~XMLEntityDecl()

Modified: xerces/c/trunk/src/xercesc/framework/XMLNotationDecl.cpp
URL: http://svn.apache.org/viewcvs/xerces/c/trunk/src/xercesc/framework/XMLNotationDecl.cpp?rev=180348&r1=180347&r2=180348&view=diff
==============================================================================
--- xerces/c/trunk/src/xercesc/framework/XMLNotationDecl.cpp (original)
+++ xerces/c/trunk/src/xercesc/framework/XMLNotationDecl.cpp Mon Jun  6 10:41:39 2005
@@ -89,6 +89,8 @@
 {
 }
 
+typedef JanitorMemFunCall<XMLNotationDecl>  CleanupType;
+
 XMLNotationDecl::XMLNotationDecl( const XMLCh* const   notName
                                 , const XMLCh* const   pubId
                                 , const XMLCh* const   sysId
@@ -102,6 +104,8 @@
     , fBaseURI(0)
     , fMemoryManager(manager)
 {
+    CleanupType cleanup(this, &XMLNotationDecl::cleanUp);
+
     try
     {
         fName = XMLString::replicate(notName, fMemoryManager);
@@ -111,12 +115,12 @@
     }
     catch(const OutOfMemoryException&)
     {
+        cleanup.release();
+
         throw;
     }
-    catch(...)
-    {
-        cleanUp();
-    }
+
+    cleanup.release();
 }
 
 XMLNotationDecl::~XMLNotationDecl()

Modified: xerces/c/trunk/src/xercesc/framework/psvi/XSValue.cpp
URL: http://svn.apache.org/viewcvs/xerces/c/trunk/src/xercesc/framework/psvi/XSValue.cpp?rev=180348&r1=180347&r2=180348&view=diff
==============================================================================
--- xerces/c/trunk/src/xercesc/framework/psvi/XSValue.cpp (original)
+++ xerces/c/trunk/src/xercesc/framework/psvi/XSValue.cpp Mon Jun  6 10:41:39 2005
@@ -122,6 +122,7 @@
 #include <xercesc/validators/schema/SchemaSymbols.hpp>
 #include <xercesc/util/OutOfMemoryException.hpp>
 #include <xercesc/util/TransService.hpp>
+#include <xercesc/util/NumberFormatException.hpp>
 
 XERCES_CPP_NAMESPACE_BEGIN
 
@@ -699,7 +700,7 @@
     {
         throw;
     }
-    catch (...)
+    catch (const NumberFormatException&)
     {
         //getActValue()/getCanonical() need to know the failure details
         //if validation is required
@@ -756,7 +757,7 @@
         return true; //parsing succeed
     }
 
-    catch (SchemaDateTimeException &e)
+    catch (const SchemaDateTimeException &e)
     {       
         status = checkTimeZoneError(datatype, e)? XSValue::st_FODT0003 : st_FOCA0002;
         return false;
@@ -765,7 +766,7 @@
     {
         throw;
     }
-    catch (...)
+    catch (const NumberFormatException&)
     {
         //getActValue()/getCanonical() need to know the failure details
         //if validation is required
@@ -1067,11 +1068,6 @@
     {
         throw;
     }
-    catch (...)
-    {
-        isValid = false; 
-        status = st_FOCA0002;
-    }
 
     if (isValid == false && status == st_Init) {
         status = st_FOCA0002;
@@ -1090,8 +1086,8 @@
     try 
     {
 
-        // All getCanonicalRepresentation does lexcial space validation only
-        // (no range checking), therefore if validation is requied,
+        // getCanonicalRepresentation does lexical space validation only
+        // (no range checking), therefore if validation is required,
         // we need to pass the content to the validate interface for complete checking
         if (toValidate && !validateNumerics(content, datatype, status, manager))
             return 0;
@@ -1131,7 +1127,7 @@
     {
         throw;
     }
-    catch (...)
+    catch (const NumberFormatException&)
     {
         status = st_FOCA0002;
         return 0;
@@ -1193,7 +1189,7 @@
     {
         throw;
     }
-    catch (...)
+    catch (const NumberFormatException&)
     {
         status = st_FOCA0002;
         return 0;
@@ -1290,11 +1286,7 @@
     {
         throw;
     }
-    catch (...)
-    {
-        status = st_FOCA0002;
-        return 0;
-    }
+
     return 0;
 }
 
@@ -1477,7 +1469,7 @@
     {
         throw;
     }
-    catch (...)
+    catch (const NumberFormatException&)
     {
         status = st_FOCA0002;
         return 0; 
@@ -1566,7 +1558,7 @@
     {
         throw;
     }
-    catch (...)
+    catch (const NumberFormatException&)
     {
         status = st_FOCA0002;
         return 0; 
@@ -1681,11 +1673,7 @@
     {
         throw;
     }
-    catch (...)
-    {
-        status = st_FOCA0002;
-        return 0; 
-    }
+
     return 0; 
 }
 

Modified: xerces/c/trunk/src/xercesc/internal/DGXMLScanner.cpp
URL: http://svn.apache.org/viewcvs/xerces/c/trunk/src/xercesc/internal/DGXMLScanner.cpp?rev=180348&r1=180347&r2=180348&view=diff
==============================================================================
--- xerces/c/trunk/src/xercesc/internal/DGXMLScanner.cpp (original)
+++ xerces/c/trunk/src/xercesc/internal/DGXMLScanner.cpp Mon Jun  6 10:41:39 2005
@@ -45,6 +45,11 @@
 
 XERCES_CPP_NAMESPACE_BEGIN
 
+
+typedef JanitorMemFunCall<DGXMLScanner> CleanupType;
+typedef JanitorMemFunCall<ReaderMgr>    ReaderMgrResetType;
+
+
 // ---------------------------------------------------------------------------
 //  DGXMLScanner: Constructors and Destructor
 // ---------------------------------------------------------------------------
@@ -61,29 +66,22 @@
     , fAttDefRegistry(0)
     , fUndeclaredAttrRegistry(0)
 {
+    CleanupType cleanup(this, &DGXMLScanner::cleanUp);
+
     try
     {
         commonInit();
-
-        if (valToAdopt)
-        {
-            if (!valToAdopt->handlesDTD())
-               ThrowXMLwithMemMgr(RuntimeException, XMLExcepts::Gen_NoDTDValidator, fMemoryManager);
-        }
-        else
-        {
-            fValidator = fDTDValidator;
-        }
     }
     catch(const OutOfMemoryException&)
     {
+        // Don't cleanup when out of memory, since executing the
+        // code can cause problems.
+        cleanup.release();
+
         throw;
     }
-    catch(...)
-    {
-        cleanUp();
-        throw;
-    }
+
+    cleanup.release();
 }
 
 DGXMLScanner::DGXMLScanner( XMLDocumentHandler* const docHandler
@@ -103,29 +101,22 @@
     , fAttDefRegistry(0)
     , fUndeclaredAttrRegistry(0)
 {
+    CleanupType cleanup(this, &DGXMLScanner::cleanUp);
+
     try
     {	
         commonInit();
-
-        if (valToAdopt)
-        {
-            if (!valToAdopt->handlesDTD())
-               ThrowXMLwithMemMgr(RuntimeException, XMLExcepts::Gen_NoDTDValidator, fMemoryManager);
-        }
-        else
-        {
-            fValidator = fDTDValidator;
-        }
     }
     catch(const OutOfMemoryException&)
     {
+        // Don't cleanup when out of memory, since executing the
+        // code can cause problems.
+        cleanup.release();
+
         throw;
     }
-    catch(...)
-    {
-        cleanUp();
-        throw;
-    }
+
+    cleanup.release();
 }
 
 DGXMLScanner::~DGXMLScanner()
@@ -159,6 +150,8 @@
     //  any previous progressive scan tokens.
     fSequenceId++;
 
+    ReaderMgrResetType  resetReaderMgr(&fReaderMgr, &ReaderMgr::reset);
+
     try
     {
         //  Reset the scanner and its plugged in stuff for a new run. This
@@ -205,9 +198,6 @@
         // If we have a document handler, then call the end document
         if (fDocHandler)
             fDocHandler->endDocument();
-
-        // Reset the reader manager to close all files, sockets, etc...
-        fReaderMgr.reset();
     }
     //  NOTE:
     //
@@ -216,13 +206,11 @@
     //  to find out the position in the XML source of the error.
     catch(const XMLErrs::Codes)
     {
-        // This is a 'first fatal error' type exit, so reset and fall through
-        fReaderMgr.reset();
+        // This is a 'first failure' exception, so fall through
     }
     catch(const XMLValid::Codes)
     {
-        // This is a 'first fatal error' type exit, so reset and fall through
-        fReaderMgr.reset();
+        // This is a 'first fatal error' type exit, so fall through
     }
     catch(const XMLException& excToCatch)
     {
@@ -255,26 +243,21 @@
         }
         catch(const OutOfMemoryException&)
         {
+            // This is a special case for out-of-memory
+            // conditions, because resetting the ReaderMgr
+            // can be problematic.
+            resetReaderMgr.release();
+
             throw;
         }
-        catch(...)
-        {
-            // Flush the reader manager and rethrow user's error
-            fReaderMgr.reset();
-            throw;
-        }
-
-        // If it returned, then reset the reader manager and fall through
-        fReaderMgr.reset();
     }
     catch(const OutOfMemoryException&)
     {
-        throw;
-    }
-    catch(...)
-    {
-        // Reset and rethrow
-        fReaderMgr.reset();
+        // This is a special case for out-of-memory
+        // conditions, because resetting the ReaderMgr
+        // can be problematic.
+        resetReaderMgr.release();
+
         throw;
     }
 }
@@ -290,6 +273,8 @@
     unsigned int orgReader;
     XMLTokens curToken;
 
+    ReaderMgrResetType  resetReaderMgr(&fReaderMgr, &ReaderMgr::reset);
+
     bool retVal = true;
 
     try
@@ -396,15 +381,13 @@
     //  to find out the position in the XML source of the error.
     catch(const XMLErrs::Codes)
     {
-        // This is a 'first failure' exception, so reset and return failure
-        fReaderMgr.reset();
-        return false;
+        // This is a 'first failure' exception, so return failure
+        retVal = false;
     }
     catch(const XMLValid::Codes)
     {
-        // This is a 'first fatal error' type exit, so reset and reuturn failure
-        fReaderMgr.reset();
-        return false;
+        // This is a 'first fatal error' type exit, so return failure
+        retVal = false;
     }
     catch(const XMLException& excToCatch)
     {
@@ -437,33 +420,30 @@
         }
         catch(const OutOfMemoryException&)
         {
-            throw;
-        }
-        catch(...)
-        {
-            // Reset and rethrow user error
-            fReaderMgr.reset();
+            // This is a special case for out-of-memory
+            // conditions, because resetting the ReaderMgr
+            // can be problematic.
+            resetReaderMgr.release();
+
             throw;
         }
 
-        // Reset and return failure
-        fReaderMgr.reset();
-        return false;
+        retVal = false;
     }
     catch(const OutOfMemoryException&)
     {
-        throw;
-    }
-    catch(...)
-    {
-        // Reset and rethrow original error
-        fReaderMgr.reset();
+        // This is a special case for out-of-memory
+        // conditions, because resetting the ReaderMgr
+        // can be problematic.
+        resetReaderMgr.release();
+
         throw;
     }
 
-    // If we hit the end, then flush the reader manager
-    if (!retVal)
-        fReaderMgr.reset();
+    // If we are not at the end, release the object that will
+    // reset the ReaderMgr.
+    if (retVal)
+        resetReaderMgr.release();
 
     return retVal;
 }
@@ -1678,6 +1658,8 @@
 {
     Grammar* loadedGrammar = 0;
 
+    ReaderMgrResetType  resetReaderMgr(&fReaderMgr, &ReaderMgr::reset);
+
     try
     {
         fGrammarResolver->cacheGrammarFromParse(false);
@@ -1697,9 +1679,6 @@
         if (grammarType == Grammar::DTDGrammarType) {
             loadedGrammar = loadDTDGrammar(src, toCache);
         }
-
-        // Reset the reader manager to close all files, sockets, etc...
-        fReaderMgr.reset();
     }
     //  NOTE:
     //
@@ -1708,14 +1687,11 @@
     //  to find out the position in the XML source of the error.
     catch(const XMLErrs::Codes)
     {
-        // This is a 'first fatal error' type exit, so reset and fall through
-        fReaderMgr.reset();
+        // This is a 'first failure' exception, so fall through
     }
     catch(const XMLValid::Codes)
     {
-        // This is a 'first fatal error' type exit, so reset and fall through
-        fReaderMgr.reset();
-
+        // This is a 'first fatal error' type exit, so fall through
     }
     catch(const XMLException& excToCatch)
     {
@@ -1747,26 +1723,21 @@
         }
         catch(const OutOfMemoryException&)
         {
+            // This is a special case for out-of-memory
+            // conditions, because resetting the ReaderMgr
+            // can be problematic.
+            resetReaderMgr.release();
+
             throw;
         }
-        catch(...)
-        {
-            // Flush the reader manager and rethrow user's error
-            fReaderMgr.reset();
-            throw;
-        }
-
-        // If it returned, then reset the reader manager and fall through
-        fReaderMgr.reset();
     }
     catch(const OutOfMemoryException&)
     {
-        throw;
-    }
-    catch(...)
-    {
-        // Reset and rethrow
-        fReaderMgr.reset();
+        // This is a special case for out-of-memory
+        // conditions, because resetting the ReaderMgr
+        // can be problematic.
+        resetReaderMgr.release();
+
         throw;
     }
 
@@ -1893,7 +1864,6 @@
 //  it redundantly in multiple constructors.
 void DGXMLScanner::commonInit()
 {
-
     //  And we need one for the raw attribute scan. This just stores key/
     //  value string pairs (prior to any processing.)
     fAttrNSList = new (fMemoryManager) ValueVectorOf<XMLAttr*>(8, fMemoryManager);
@@ -1910,6 +1880,16 @@
     (
         7, false, new (fMemoryManager)HashXMLCh(), fMemoryManager
     );
+
+    if (fValidator)
+    {
+        if (!fValidator->handlesDTD())
+           ThrowXMLwithMemMgr(RuntimeException, XMLExcepts::Gen_NoDTDValidator, fMemoryManager);
+    }
+    else
+    {
+        fValidator = fDTDValidator;
+    }
 }
 
 void DGXMLScanner::cleanUp()

Modified: xerces/c/trunk/src/xercesc/internal/IGXMLScanner.cpp
URL: http://svn.apache.org/viewcvs/xerces/c/trunk/src/xercesc/internal/IGXMLScanner.cpp?rev=180348&r1=180347&r2=180348&view=diff
==============================================================================
--- xerces/c/trunk/src/xercesc/internal/IGXMLScanner.cpp (original)
+++ xerces/c/trunk/src/xercesc/internal/IGXMLScanner.cpp Mon Jun  6 10:41:39 2005
@@ -47,6 +47,11 @@
 
 XERCES_CPP_NAMESPACE_BEGIN
 
+
+typedef JanitorMemFunCall<IGXMLScanner> CleanupType;
+typedef JanitorMemFunCall<ReaderMgr>    ReaderMgrResetType;
+
+
 // ---------------------------------------------------------------------------
 //  IGXMLScanner: Constructors and Destructor
 // ---------------------------------------------------------------------------
@@ -79,23 +84,22 @@
     , fPSVIElement(0)
     , fErrorStack(0)        
 {
+    CleanupType cleanup(this, &IGXMLScanner::cleanUp);
+
     try
     {
-         commonInit();
-
-         // use fDTDValidator as the default validator
-         if (!valToAdopt)
-             fValidator = fDTDValidator;
+        commonInit();
     }
     catch(const OutOfMemoryException&)
     {
+        // Don't cleanup when out of memory, since executing the
+        // code can cause problems.
+        cleanup.release();
+
         throw;
     }
-    catch(...)
-    {
-        cleanUp();
-        throw;
-    }
+
+    cleanup.release();
 }
 
 IGXMLScanner::IGXMLScanner( XMLDocumentHandler* const docHandler
@@ -131,23 +135,22 @@
     , fPSVIElement(0)
     , fErrorStack(0)       
 {
+    CleanupType cleanup(this, &IGXMLScanner::cleanUp);
+
     try
     {	
         commonInit();
-
-        //use fDTDValidator as the default validator
-        if (!valToAdopt)
-            fValidator = fDTDValidator;
     }
     catch(const OutOfMemoryException&)
     {
+        // Don't cleanup when out of memory, since executing the
+        // code can cause problems.
+        cleanup.release();
+
         throw;
     }
-    catch(...)
-    {
-        cleanUp();
-        throw;
-    }
+
+    cleanup.release();
 }
 
 IGXMLScanner::~IGXMLScanner()
@@ -181,6 +184,8 @@
     //  any previous progressive scan tokens.
     fSequenceId++;
 
+    ReaderMgrResetType  resetReaderMgr(&fReaderMgr, &ReaderMgr::reset);
+
     try
     {
         //  Reset the scanner and its plugged in stuff for a new run. This
@@ -230,9 +235,6 @@
 
         //cargill debug:
         //fGrammarResolver->getXSModel();
-
-        // Reset the reader manager to close all files, sockets, etc...
-        fReaderMgr.reset();
     }
     //  NOTE:
     //
@@ -241,13 +243,11 @@
     //  to find out the position in the XML source of the error.
     catch(const XMLErrs::Codes)
     {
-        // This is a 'first fatal error' type exit, so reset and fall through
-        fReaderMgr.reset();
+        // This is a 'first failure' exception, so fall through
     }
     catch(const XMLValid::Codes)
     {
-        // This is a 'first fatal error' type exit, so reset and fall through
-        fReaderMgr.reset();
+        // This is a 'first fatal error' type exit, so fall through
     }
     catch(const XMLException& excToCatch)
     {
@@ -280,26 +280,21 @@
         }
         catch(const OutOfMemoryException&)
         {
+            // This is a special case for out-of-memory
+            // conditions, because resetting the ReaderMgr
+            // can be problematic.
+            resetReaderMgr.release();
+
             throw;
         }
-        catch(...)
-        {
-            // Flush the reader manager and rethrow user's error
-            fReaderMgr.reset();
-            throw;
-        }
-
-        // If it returned, then reset the reader manager and fall through
-        fReaderMgr.reset();
     }
     catch(const OutOfMemoryException&)
     {
-        throw;
-    }
-    catch(...)
-    {
-        // Reset and rethrow
-        fReaderMgr.reset();
+        // This is a special case for out-of-memory
+        // conditions, because resetting the ReaderMgr
+        // can be problematic.
+        resetReaderMgr.release();
+
         throw;
     }
 }
@@ -315,6 +310,8 @@
     unsigned int orgReader;
     XMLTokens curToken;
 
+    ReaderMgrResetType  resetReaderMgr(&fReaderMgr, &ReaderMgr::reset);
+
     bool retVal = true;
 
     try
@@ -427,15 +424,13 @@
     //  to find out the position in the XML source of the error.
     catch(const XMLErrs::Codes)
     {
-        // This is a 'first failure' exception, so reset and return failure
-        fReaderMgr.reset();
-        return false;
+        // This is a 'first failure' exception so return failure
+        retVal = false;
     }
     catch(const XMLValid::Codes)
     {
-        // This is a 'first fatal error' type exit, so reset and reuturn failure
-        fReaderMgr.reset();
-        return false;
+        // This is a 'first fatal error' type exit, so return failure
+        retVal = false;
     }
     catch(const XMLException& excToCatch)
     {
@@ -468,33 +463,30 @@
         }
         catch(const OutOfMemoryException&)
         {
-            throw;
-        }
-        catch(...)
-        {
-            // Reset and rethrow user error
-            fReaderMgr.reset();
+            // This is a special case for out-of-memory
+            // conditions, because resetting the ReaderMgr
+            // can be problematic.
+            resetReaderMgr.release();
+
             throw;
         }
 
-        // Reset and return failure
-        fReaderMgr.reset();
-        return false;
+        retVal = false;
     }
     catch(const OutOfMemoryException&)
     {
-        throw;
-    }
-    catch(...)
-    {
-        // Reset and rethrow original error
-        fReaderMgr.reset();
+        // This is a special case for out-of-memory
+        // conditions, because resetting the ReaderMgr
+        // can be problematic.
+        resetReaderMgr.release();
+
         throw;
     }
 
-    // If we hit the end, then flush the reader manager
-    if (!retVal)
-        fReaderMgr.reset();
+    // If we are not at the end, release the object that will
+    // reset the ReaderMgr.
+    if (retVal)
+        resetReaderMgr.release();
 
     return retVal;
 }
@@ -552,6 +544,10 @@
         7, false, new (fMemoryManager)HashXMLCh(), fMemoryManager
     );
     fPSVIAttrList = new (fMemoryManager) PSVIAttributeList(fMemoryManager);
+
+    // use fDTDValidator as the default validator
+    if (!fValidator)
+        fValidator = fDTDValidator;
 }
 
 void IGXMLScanner::cleanUp()
@@ -2945,6 +2941,8 @@
 {
     Grammar* loadedGrammar = 0;
 
+    ReaderMgrResetType  resetReaderMgr(&fReaderMgr, &ReaderMgr::reset);
+
     try
     {
         fGrammarResolver->cacheGrammarFromParse(false);
@@ -2971,9 +2969,6 @@
         else if (grammarType == Grammar::DTDGrammarType) {
             loadedGrammar = loadDTDGrammar(src, toCache);
         }
-
-        // Reset the reader manager to close all files, sockets, etc...
-        fReaderMgr.reset();
     }
     //  NOTE:
     //
@@ -2982,14 +2977,11 @@
     //  to find out the position in the XML source of the error.
     catch(const XMLErrs::Codes)
     {
-        // This is a 'first fatal error' type exit, so reset and fall through
-        fReaderMgr.reset();
+        // This is a 'first fatal error' type exit, so fall through
     }
     catch(const XMLValid::Codes)
     {
-        // This is a 'first fatal error' type exit, so reset and fall through
-        fReaderMgr.reset();
-
+        // This is a 'first fatal error' type exit, so fall through
     }
     catch(const XMLException& excToCatch)
     {
@@ -3021,26 +3013,21 @@
         }
         catch(const OutOfMemoryException&)
         {
+            // This is a special case for out-of-memory
+            // conditions, because resetting the ReaderMgr
+            // can be problematic.
+            resetReaderMgr.release();
+
             throw;
         }
-        catch(...)
-        {
-            // Flush the reader manager and rethrow user's error
-            fReaderMgr.reset();
-            throw;
-        }
-
-        // If it returned, then reset the reader manager and fall through
-        fReaderMgr.reset();
     }
     catch(const OutOfMemoryException&)
     {
-        throw;
-    }
-    catch(...)
-    {
-        // Reset and rethrow
-        fReaderMgr.reset();
+        // This is a special case for out-of-memory
+        // conditions, because resetting the ReaderMgr
+        // can be problematic.
+        resetReaderMgr.release();
+
         throw;
     }
 

Modified: xerces/c/trunk/src/xercesc/internal/ReaderMgr.cpp
URL: http://svn.apache.org/viewcvs/xerces/c/trunk/src/xercesc/internal/ReaderMgr.cpp?rev=180348&r1=180347&r2=180348&view=diff
==============================================================================
--- xerces/c/trunk/src/xercesc/internal/ReaderMgr.cpp (original)
+++ xerces/c/trunk/src/xercesc/internal/ReaderMgr.cpp Mon Jun  6 10:41:39 2005
@@ -387,6 +387,8 @@
     if (!newStream)
         return 0;
 
+    Janitor<BinInputStream>   streamJanitor(newStream);
+
     //
     //  Create a new reader and return it. If the source has an encoding that
     //  it wants to force, then we call the constructor that does that.
@@ -438,19 +440,14 @@
     }
     catch(const OutOfMemoryException&)
     {
-        throw;
-    }
-    catch (...) //NetAccessorException&
-    {
-        delete newStream;
+        streamJanitor.release();
+
         throw;
     }
 
-    // If it failed for any reason, then return zero.
-    if (!retVal) {
-        delete newStream;
-        return 0;
-    }
+    assert(retVal);
+
+    streamJanitor.release();
 
     // Set the next available reader number on this reader
     retVal->setReaderNum(fNextReaderNum++);

Modified: xerces/c/trunk/src/xercesc/internal/SGXMLScanner.cpp
URL: http://svn.apache.org/viewcvs/xerces/c/trunk/src/xercesc/internal/SGXMLScanner.cpp?rev=180348&r1=180347&r2=180348&view=diff
==============================================================================
--- xerces/c/trunk/src/xercesc/internal/SGXMLScanner.cpp (original)
+++ xerces/c/trunk/src/xercesc/internal/SGXMLScanner.cpp Mon Jun  6 10:41:39 2005
@@ -51,6 +51,11 @@
 
 inline XMLAttDefList& getAttDefList(ComplexTypeInfo* currType, XMLElementDecl* elemDecl);
 
+
+typedef JanitorMemFunCall<SGXMLScanner> CleanupType;
+typedef JanitorMemFunCall<ReaderMgr>    ReaderMgrResetType;
+
+
 // ---------------------------------------------------------------------------
 //  SGXMLScanner: Constructors and Destructor
 // ---------------------------------------------------------------------------
@@ -80,29 +85,22 @@
     , fPSVIElement(0)
     , fErrorStack(0)       
 {
+    CleanupType cleanup(this, &SGXMLScanner::cleanUp);
+
     try
     {
          commonInit();
-
-         if (valToAdopt)
-         {
-             if (!valToAdopt->handlesSchema())
-                ThrowXMLwithMemMgr(RuntimeException, XMLExcepts::Gen_NoSchemaValidator, fMemoryManager);
-         }
-         else
-         {
-             fValidator = fSchemaValidator;
-         }
     }
     catch(const OutOfMemoryException&)
     {
+        // Don't cleanup when out of memory, since executing the
+        // code can cause problems.
+        cleanup.release();
+
         throw;
     }
-    catch(...)
-    {
-        cleanUp();
-        throw;
-    }
+
+    cleanup.release();
 }
 
 SGXMLScanner::SGXMLScanner( XMLDocumentHandler* const docHandler
@@ -135,29 +133,22 @@
     , fPSVIElement(0)
     , fErrorStack(0)        
 {
+    CleanupType cleanup(this, &SGXMLScanner::cleanUp);
+
     try
     {	
         commonInit();
-
-         if (valToAdopt)
-         {
-             if (!valToAdopt->handlesSchema())
-                ThrowXMLwithMemMgr(RuntimeException, XMLExcepts::Gen_NoSchemaValidator, fMemoryManager);
-         }
-         else
-         {
-             fValidator = fSchemaValidator;
-         }
     }
     catch(const OutOfMemoryException&)
     {
+        // Don't cleanup when out of memory, since executing the
+        // code can cause problems.
+        cleanup.release();
+
         throw;
     }
-    catch(...)
-    {
-        cleanUp();
-        throw;
-    }
+
+    cleanup.release();
 }
 
 SGXMLScanner::~SGXMLScanner()
@@ -187,6 +178,8 @@
     //  any previous progressive scan tokens.
     fSequenceId++;
 
+    ReaderMgrResetType  resetReaderMgr(&fReaderMgr, &ReaderMgr::reset);
+
     try
     {
         //  Reset the scanner and its plugged in stuff for a new run. This
@@ -233,9 +226,6 @@
         // If we have a document handler, then call the end document
         if (fDocHandler)
             fDocHandler->endDocument();
-
-        // Reset the reader manager to close all files, sockets, etc...
-        fReaderMgr.reset();
     }
     //  NOTE:
     //
@@ -244,13 +234,11 @@
     //  to find out the position in the XML source of the error.
     catch(const XMLErrs::Codes)
     {
-        // This is a 'first fatal error' type exit, so reset and fall through
-        fReaderMgr.reset();
+        // This is a 'first failure' exception, so fall through
     }
     catch(const XMLValid::Codes)
     {
-        // This is a 'first fatal error' type exit, so reset and fall through
-        fReaderMgr.reset();
+        // This is a 'first fatal error' type exit, so fall through
     }
     catch(const XMLException& excToCatch)
     {
@@ -283,26 +271,21 @@
         }
         catch(const OutOfMemoryException&)
         {
+            // This is a special case for out-of-memory
+            // conditions, because resetting the ReaderMgr
+            // can be problematic.
+            resetReaderMgr.release();
+
             throw;
         }
-        catch(...)
-        {
-            // Flush the reader manager and rethrow user's error
-            fReaderMgr.reset();
-            throw;
-        }
-
-        // If it returned, then reset the reader manager and fall through
-        fReaderMgr.reset();
     }
     catch(const OutOfMemoryException&)
     {
-        throw;
-    }
-    catch(...)
-    {
-        // Reset and rethrow
-        fReaderMgr.reset();
+        // This is a special case for out-of-memory
+        // conditions, because resetting the ReaderMgr
+        // can be problematic.
+        resetReaderMgr.release();
+
         throw;
     }
 }
@@ -318,6 +301,8 @@
     unsigned int orgReader;
     XMLTokens curToken;
 
+    ReaderMgrResetType  resetReaderMgr(&fReaderMgr, &ReaderMgr::reset);
+
     bool retVal = true;
 
     try
@@ -427,15 +412,13 @@
     //  to find out the position in the XML source of the error.
     catch(const XMLErrs::Codes)
     {
-        // This is a 'first failure' exception, so reset and return failure
-        fReaderMgr.reset();
-        return false;
+        // This is a 'first failure' exception, so return failure
+        retVal = false;
     }
     catch(const XMLValid::Codes)
     {
-        // This is a 'first fatal error' type exit, so reset and reuturn failure
-        fReaderMgr.reset();
-        return false;
+        // This is a 'first fatal error' type exit, so return failure
+        retVal = false;
     }
     catch(const XMLException& excToCatch)
     {
@@ -468,33 +451,30 @@
         }
         catch(const OutOfMemoryException&)
         {
-            throw;
-        }
-        catch(...)
-        {
-            // Reset and rethrow user error
-            fReaderMgr.reset();
+            // This is a special case for out-of-memory
+            // conditions, because resetting the ReaderMgr
+            // can be problematic.
+            resetReaderMgr.release();
+
             throw;
         }
 
-        // Reset and return failure
-        fReaderMgr.reset();
-        return false;
+        retVal = false;
     }
     catch(const OutOfMemoryException&)
     {
-        throw;
-    }
-    catch(...)
-    {
-        // Reset and rethrow original error
-        fReaderMgr.reset();
+        // This is a special case for out-of-memory
+        // conditions, because resetting the ReaderMgr
+        // can be problematic.
+        resetReaderMgr.release();
+
         throw;
     }
 
-    // If we hit the end, then flush the reader manager
-    if (!retVal)
-        fReaderMgr.reset();
+    // If we are not at the end, release the object that will
+    // reset the ReaderMgr.
+    if (retVal)
+        resetReaderMgr.release();
 
     return retVal;
 }
@@ -1890,6 +1870,8 @@
 {
     Grammar* loadedGrammar = 0;
 
+    ReaderMgrResetType  resetReaderMgr(&fReaderMgr, &ReaderMgr::reset);
+
     try
     {
         fGrammarResolver->cacheGrammarFromParse(false);
@@ -1913,9 +1895,6 @@
         if (grammarType == Grammar::SchemaGrammarType) {
             loadedGrammar = loadXMLSchemaGrammar(src, toCache);
         }
-
-        // Reset the reader manager to close all files, sockets, etc...
-        fReaderMgr.reset();
     }
     //  NOTE:
     //
@@ -1924,14 +1903,11 @@
     //  to find out the position in the XML source of the error.
     catch(const XMLErrs::Codes)
     {
-        // This is a 'first fatal error' type exit, so reset and fall through
-        fReaderMgr.reset();
+        // This is a 'first failure' exception, so fall through
     }
     catch(const XMLValid::Codes)
     {
-        // This is a 'first fatal error' type exit, so reset and fall through
-        fReaderMgr.reset();
-
+        // This is a 'first fatal error' type exit, so fall through
     }
     catch(const XMLException& excToCatch)
     {
@@ -1963,26 +1939,21 @@
         }
         catch(const OutOfMemoryException&)
         {
+            // This is a special case for out-of-memory
+            // conditions, because resetting the ReaderMgr
+            // can be problematic.
+            resetReaderMgr.release();
+
             throw;
         }
-        catch(...)
-        {
-            // Flush the reader manager and rethrow user's error
-            fReaderMgr.reset();
-            throw;
-        }
-
-        // If it returned, then reset the reader manager and fall through
-        fReaderMgr.reset();
     }
     catch(const OutOfMemoryException&)
     {
-        throw;
-    }
-    catch(...)
-    {
-        // Reset and rethrow
-        fReaderMgr.reset();
+        // This is a special case for out-of-memory
+        // conditions, because resetting the ReaderMgr
+        // can be problematic.
+        resetReaderMgr.release();
+
         throw;
     }
 
@@ -2035,6 +2006,16 @@
         7, false, new (fMemoryManager)HashXMLCh(), fMemoryManager
     );
     fPSVIAttrList = new (fMemoryManager) PSVIAttributeList(fMemoryManager);
+
+    if (fValidator)
+    {
+        if (!fValidator->handlesSchema())
+            ThrowXMLwithMemMgr(RuntimeException, XMLExcepts::Gen_NoSchemaValidator, fMemoryManager);
+    }
+    else
+    {
+        fValidator = fSchemaValidator;
+    }
 }
 
 void SGXMLScanner::cleanUp()

Modified: xerces/c/trunk/src/xercesc/internal/WFXMLScanner.cpp
URL: http://svn.apache.org/viewcvs/xerces/c/trunk/src/xercesc/internal/WFXMLScanner.cpp?rev=180348&r1=180347&r2=180348&view=diff
==============================================================================
--- xerces/c/trunk/src/xercesc/internal/WFXMLScanner.cpp (original)
+++ xerces/c/trunk/src/xercesc/internal/WFXMLScanner.cpp Mon Jun  6 10:41:39 2005
@@ -39,6 +39,12 @@
 // ---------------------------------------------------------------------------
 //  WFXMLScanner: Constructors and Destructor
 // ---------------------------------------------------------------------------
+
+
+typedef JanitorMemFunCall<WFXMLScanner> CleanupType;
+typedef JanitorMemFunCall<ReaderMgr>    ReaderMgrResetType;
+
+
 WFXMLScanner::WFXMLScanner( XMLValidator* const  valToAdopt
                           , GrammarResolver* const grammarResolver
                           , MemoryManager* const manager) :
@@ -51,19 +57,22 @@
     , fAttrNSList(0)
     , fElementLookup(0)
 {
+    CleanupType cleanup(this, &WFXMLScanner::cleanUp);
+
     try
     {
         commonInit();
     }
     catch(const OutOfMemoryException&)
     {
+        // Don't cleanup when out of memory, since executing the
+        // code can cause problems.
+        cleanup.release();
+
         throw;
     }
-    catch(...)
-    {
-        cleanUp();
-        throw;
-    }
+
+    cleanup.release();
 }
 
 WFXMLScanner::WFXMLScanner( XMLDocumentHandler* const docHandler
@@ -82,19 +91,22 @@
     , fAttrNSList(0)
     , fElementLookup(0)
 {
+    CleanupType cleanup(this, &WFXMLScanner::cleanUp);
+
     try
     {	
         commonInit();
     }
     catch(const OutOfMemoryException&)
     {
+        // Don't cleanup when out of memory, since executing the
+        // code can cause problems.
+        cleanup.release();
+
         throw;
     }
-    catch(...)
-    {
-        cleanUp();
-        throw;
-    }
+
+    cleanup.release();
 }
 
 WFXMLScanner::~WFXMLScanner()
@@ -124,6 +136,8 @@
     //  any previous progressive scan tokens.
     fSequenceId++;
 
+    ReaderMgrResetType  resetReaderMgr(&fReaderMgr, &ReaderMgr::reset);
+
     try
     {
         //  Reset the scanner and its plugged in stuff for a new run. This
@@ -159,9 +173,6 @@
         // If we have a document handler, then call the end document
         if (fDocHandler)
             fDocHandler->endDocument();
-
-        // Reset the reader manager to close all files, sockets, etc...
-        fReaderMgr.reset();
     }
     //  NOTE:
     //
@@ -170,13 +181,11 @@
     //  to find out the position in the XML source of the error.
     catch(const XMLErrs::Codes)
     {
-        // This is a 'first fatal error' type exit, so reset and fall through
-        fReaderMgr.reset();
+        // This is a 'first failure' exception, so fall through
     }
     catch(const XMLValid::Codes)
     {
-        // This is a 'first fatal error' type exit, so reset and fall through
-        fReaderMgr.reset();
+        // This is a 'first fatal error' type exit, so fall through
     }
     catch(const XMLException& excToCatch)
     {
@@ -209,26 +218,21 @@
         }
         catch(const OutOfMemoryException&)
         {
+            // This is a special case for out-of-memory
+            // conditions, because resetting the ReaderMgr
+            // can be problematic.
+            resetReaderMgr.release();
+
             throw;
         }
-        catch(...)
-        {
-            // Flush the reader manager and rethrow user's error
-            fReaderMgr.reset();
-            throw;
-        }
-
-        // If it returned, then reset the reader manager and fall through
-        fReaderMgr.reset();
     }
     catch(const OutOfMemoryException&)
     {
-        throw;
-    }
-    catch(...)
-    {
-        // Reset and rethrow
-        fReaderMgr.reset();
+        // This is a special case for out-of-memory
+        // conditions, because resetting the ReaderMgr
+        // can be problematic.
+        resetReaderMgr.release();
+
         throw;
     }
 }
@@ -245,6 +249,8 @@
     XMLTokens curToken;
     bool retVal = true;
 
+    ReaderMgrResetType  resetReaderMgr(&fReaderMgr, &ReaderMgr::reset);
+
     try
     {
         while (true)
@@ -341,15 +347,13 @@
     //  to find out the position in the XML source of the error.
     catch(const XMLErrs::Codes)
     {
-        // This is a 'first failure' exception, so reset and return failure
-        fReaderMgr.reset();
-        return false;
+        // This is a 'first failure' exception, so return failure
+        retVal = false;
     }
     catch(const XMLValid::Codes)
     {
-        // This is a 'first fatal error' type exit, so reset and reuturn failure
-        fReaderMgr.reset();
-        return false;
+        // This is a 'first fatal error' type exit, so return failure
+        retVal = false;
     }
     catch(const XMLException& excToCatch)
     {
@@ -382,33 +386,26 @@
         }
         catch(const OutOfMemoryException&)
         {
-            throw;
-        }
-        catch(...)
-        {
-            // Reset and rethrow user error
-            fReaderMgr.reset();
+            // This is a special case for out-of-memory
+            // conditions, because resetting the ReaderMgr
+            // can be problematic.
+            resetReaderMgr.release();
+
             throw;
         }
 
-        // Reset and return failure
-        fReaderMgr.reset();
-        return false;
+        // Return failure
+        retVal = false;
     }
     catch(const OutOfMemoryException&)
     {
         throw;
     }
-    catch(...)
-    {
-        // Reset and rethrow original error
-        fReaderMgr.reset();
-        throw;
-    }
 
-    // If we hit the end, then flush the reader manager
-    if (!retVal)
-        fReaderMgr.reset();
+    // If we are not at the end, release the object that will
+    // reset the ReaderMgr.
+    if (retVal)
+        resetReaderMgr.release();
 
     return retVal;
 }

Modified: xerces/c/trunk/src/xercesc/internal/XMLGrammarPoolImpl.cpp
URL: http://svn.apache.org/viewcvs/xerces/c/trunk/src/xercesc/internal/XMLGrammarPoolImpl.cpp?rev=180348&r1=180347&r2=180348&view=diff
==============================================================================
--- xerces/c/trunk/src/xercesc/internal/XMLGrammarPoolImpl.cpp (original)
+++ xerces/c/trunk/src/xercesc/internal/XMLGrammarPoolImpl.cpp Mon Jun  6 10:41:39 2005
@@ -386,7 +386,11 @@
     {
         ThrowXMLwithMemMgr(XSerializationException, XMLExcepts::XSer_GrammarPool_NotEmpty, memMgr);
     }
-    
+
+    // This object will take care of cleaning up if an exception is
+    // thrown during deserialization.
+    JanitorMemFunCall<XMLGrammarPoolImpl>   cleanup(this, &XMLGrammarPoolImpl::cleanUp);
+
     try 
     {
         XSerializeEngine  serEng(binIn, this);
@@ -426,18 +430,30 @@
     }
     catch(const OutOfMemoryException&)
     {
+        // This is a special case, because we don't want
+        // to execute cleanup code on out-of-memory
+        // conditions.
+        cleanup.release();
+
         throw;
     }
-    catch(...)
-    {
-        fLocked = false; // need to unset it so we can clean it out..
-        clear();  //clear all deserialized grammars
-        throw;
-    }
+
+    // Everything is OK, so we can release the cleanup object.
+    cleanup.release();
+
     if (fLocked) 
     {
         createXSModel();              
     }
+}
+
+
+void
+XMLGrammarPoolImpl::cleanUp()
+{
+    fLocked = false;
+
+    clear();
 }
 
 

Modified: xerces/c/trunk/src/xercesc/internal/XMLGrammarPoolImpl.hpp
URL: http://svn.apache.org/viewcvs/xerces/c/trunk/src/xercesc/internal/XMLGrammarPoolImpl.hpp?rev=180348&r1=180347&r2=180348&view=diff
==============================================================================
--- xerces/c/trunk/src/xercesc/internal/XMLGrammarPoolImpl.hpp (original)
+++ xerces/c/trunk/src/xercesc/internal/XMLGrammarPoolImpl.hpp Mon Jun  6 10:41:39 2005
@@ -325,6 +325,10 @@
 private:
 
     virtual void    createXSModel();
+
+    void
+    cleanUp();
+
     // -----------------------------------------------------------------------
     /** name  Unimplemented copy constructor and operator= */
     // -----------------------------------------------------------------------

Modified: xerces/c/trunk/src/xercesc/internal/XMLScanner.cpp
URL: http://svn.apache.org/viewcvs/xerces/c/trunk/src/xercesc/internal/XMLScanner.cpp?rev=180348&r1=180347&r2=180348&view=diff
==============================================================================
--- xerces/c/trunk/src/xercesc/internal/XMLScanner.cpp (original)
+++ xerces/c/trunk/src/xercesc/internal/XMLScanner.cpp Mon Jun  6 10:41:39 2005
@@ -134,6 +134,11 @@
     }
 }
 
+
+typedef JanitorMemFunCall<XMLScanner>   CleanupType;
+typedef JanitorMemFunCall<ReaderMgr>    ReaderMgrResetType;
+
+
 // ---------------------------------------------------------------------------
 //  XMLScanner: Constructors and Destructor
 // ---------------------------------------------------------------------------
@@ -212,12 +217,22 @@
     , fWSNormalizeBuf(1023, manager)
     , fElemStack(manager)   
 {
-   commonInit();
+    CleanupType cleanup(this, &XMLScanner::cleanUp);
 
-   if (fValidator) {
-       fValidatorFromUser = true;
-       initValidator(fValidator);
-   }
+    try
+    {
+        commonInit();
+    }
+    catch(const OutOfMemoryException&)
+    {
+        // Don't cleanup when out of memory, since executing the
+        // code can cause problems.
+        cleanup.release();
+
+        throw;
+    }
+
+    cleanup.release();
 }
 
 XMLScanner::XMLScanner( XMLDocumentHandler* const  docHandler
@@ -300,28 +315,27 @@
     , fWSNormalizeBuf(1023, manager)
     , fElemStack(manager)
 {
-   commonInit();
+    CleanupType cleanup(this, &XMLScanner::cleanUp);
 
-   if (valToAdopt){
-       fValidatorFromUser = true;
-       initValidator(fValidator);
-   }
+    try
+    {
+        commonInit();
+    }
+    catch(const OutOfMemoryException&)
+    {
+        // Don't cleanup when out of memory, since executing the
+        // code can cause problems.
+        cleanup.release();
+
+        throw;
+    }
+
+    cleanup.release();
 }
 
 XMLScanner::~XMLScanner()
 {
-    delete fAttrList;
-    delete fAttrDupChkRegistry;
-    delete fValidationContext;
-    fMemoryManager->deallocate(fRootElemName);//delete [] fRootElemName;
-    fMemoryManager->deallocate(fExternalSchemaLocation);//delete [] fExternalSchemaLocation;
-    fMemoryManager->deallocate(fExternalNoNamespaceSchemaLocation);//delete [] fExternalNoNamespaceSchemaLocation;
-    // delete fUIntPool
-    for (unsigned int i=0; i<=fUIntPoolRow; i++)
-    {
-        fMemoryManager->deallocate(fUIntPool[i]);
-    }
-    fMemoryManager->deallocate(fUIntPool);
+    cleanUp();
 }
 
 
@@ -567,7 +581,9 @@
     //  any previous tokens we've returned.
     fSequenceId++;
 
-    // Reset the scanner and its plugged in stuff for a new run.  This
+    ReaderMgrResetType  resetReaderMgr(&fReaderMgr, &ReaderMgr::reset);
+
+   // Reset the scanner and its plugged in stuff for a new run.  This
     // resets all the data structures, creates the initial reader and
     // pushes it on the stack, and sets up the base document path
     scanReset(src);
@@ -597,14 +613,12 @@
     //  to find out the position in the XML source of the error.
     catch(const XMLErrs::Codes)
     {
-        // This is a 'first failure' exception so reset and return a failure
-        fReaderMgr.reset();
+        // This is a 'first failure' exception so return failure
         return false;
     }
     catch(const XMLValid::Codes)
     {
-        // This is a 'first fatal error' type exit, so reset and reuturn failure
-        fReaderMgr.reset();
+        // This is a 'first fatal error' type exit, return failure
         return false;
     }
     catch(const XMLException& excToCatch)
@@ -638,32 +652,33 @@
         }
         catch(const OutOfMemoryException&)
         {
-            throw;
-        }
-        catch(...)
-        {
-            // Reset and rethrow the user error
-            fReaderMgr.reset();
+            // This is a special case for out-of-memory
+            // conditions, because resetting the ReaderMgr
+            // can be problematic.
+            resetReaderMgr.release();
+
             throw;
         }
 
-        // Reset and return a failure
-        fReaderMgr.reset();
         return false;
     }
     catch(const OutOfMemoryException&)
     {
-        throw;
-    }
-    catch(...)
-    {
-        // Reset and rethrow original error
-        fReaderMgr.reset();
+        // This is a special case for out-of-memory
+        // conditions, because resetting the ReaderMgr
+        // can be problematic.
+        resetReaderMgr.release();
+
         throw;
     }
 
     // Fill in the caller's token to make it legal and return success
     toFill.set(fScannerId, fSequenceId);
+
+    // Release the object that will reset the ReaderMgr, since there's
+    // more to scan.
+    resetReaderMgr.release();
+
     return true;
 }
 
@@ -747,8 +762,28 @@
 
     // Register self as handler for XMLBufferFull events on the CDATA buffer
     fCDataBuf.setFullHandler(this, fBufferSize);
+
+   if (fValidator) {
+       fValidatorFromUser = true;
+       initValidator(fValidator);
+   }
 }
 
+void XMLScanner::cleanUp()
+{
+    delete fAttrList;
+    delete fAttrDupChkRegistry;
+    delete fValidationContext;
+    fMemoryManager->deallocate(fRootElemName);//delete [] fRootElemName;
+    fMemoryManager->deallocate(fExternalSchemaLocation);//delete [] fExternalSchemaLocation;
+    fMemoryManager->deallocate(fExternalNoNamespaceSchemaLocation);//delete [] fExternalNoNamespaceSchemaLocation;
+    // delete fUIntPool
+    for (unsigned int i=0; i<=fUIntPoolRow; i++)
+    {
+        fMemoryManager->deallocate(fUIntPool[i]);
+    }
+    fMemoryManager->deallocate(fUIntPool);
+}
 
 void XMLScanner::initValidator(XMLValidator* theValidator) {
 

Modified: xerces/c/trunk/src/xercesc/internal/XMLScanner.hpp
URL: http://svn.apache.org/viewcvs/xerces/c/trunk/src/xercesc/internal/XMLScanner.hpp?rev=180348&r1=180347&r2=180348&view=diff
==============================================================================
--- xerces/c/trunk/src/xercesc/internal/XMLScanner.hpp (original)
+++ xerces/c/trunk/src/xercesc/internal/XMLScanner.hpp Mon Jun  6 10:41:39 2005
@@ -1102,6 +1102,7 @@
     //  Private helper methods
     // -----------------------------------------------------------------------
     void commonInit();
+    void cleanUp();
 
     // -----------------------------------------------------------------------
     //  Private scanning methods

Modified: xerces/c/trunk/src/xercesc/parsers/AbstractDOMParser.cpp
URL: http://svn.apache.org/viewcvs/xerces/c/trunk/src/xercesc/parsers/AbstractDOMParser.cpp?rev=180348&r1=180347&r2=180348&view=diff
==============================================================================
--- xerces/c/trunk/src/xercesc/parsers/AbstractDOMParser.cpp (original)
+++ xerces/c/trunk/src/xercesc/parsers/AbstractDOMParser.cpp Mon Jun  6 10:41:39 2005
@@ -69,6 +69,12 @@
 // ---------------------------------------------------------------------------
 //  AbstractDOMParser: Constructors and Destructor
 // ---------------------------------------------------------------------------
+
+
+typedef JanitorMemFunCall<AbstractDOMParser>    CleanupType;
+typedef JanitorMemFunCall<AbstractDOMParser>    ResetInProgressType;
+
+
 AbstractDOMParser::AbstractDOMParser( XMLValidator* const   valToAdopt
                                     , MemoryManager* const  manager
                                     , XMLGrammarPool* const gramPool) :
@@ -98,19 +104,22 @@
 , fInternalSubset(fBufMgr.bidOnBuffer())
 , fPSVIHandler(0)
 {
+    CleanupType cleanup(this, &AbstractDOMParser::cleanUp);
+
     try
     {
         initialize();
     }
     catch(const OutOfMemoryException&)
     {
+        // Don't cleanup when out of memory, since executing the
+        // code can cause problems.
+        cleanup.release();
+
         throw;
     }
-    catch(...)
-    {
-       cleanUp();
-       throw;
-    }
+
+    cleanup.release();
 }
 
 
@@ -185,6 +194,12 @@
 }
 
 
+void AbstractDOMParser::resetInProgress()
+{
+    fParseInProgress = false;
+}
+
+
 void AbstractDOMParser::resetPool()
 {
     //  We cannot enter here while a regular parse is in progress.
@@ -492,21 +507,19 @@
     if (fParseInProgress)
         ThrowXMLwithMemMgr(IOException, XMLExcepts::Gen_ParseInProgress, fMemoryManager);
 
+    ResetInProgressType     resetInProgress(this, &AbstractDOMParser::resetInProgress);
+
     try
     {
         fParseInProgress = true;
         fScanner->scanDocument(source);
-        fParseInProgress = false;
     }
     catch(const OutOfMemoryException&)
     {
+        resetInProgress.release();
+
         throw;
     }    
-    catch(...)
-    {
-        fParseInProgress = false;
-        throw;
-    }
 }
 
 void AbstractDOMParser::parse(const XMLCh* const systemId)
@@ -515,21 +528,19 @@
     if (fParseInProgress)
         ThrowXMLwithMemMgr(IOException, XMLExcepts::Gen_ParseInProgress, fMemoryManager);
 
+    ResetInProgressType     resetInProgress(this, &AbstractDOMParser::resetInProgress);
+
     try
     {
         fParseInProgress = true;
         fScanner->scanDocument(systemId);
-        fParseInProgress = false;
     }
     catch(const OutOfMemoryException&)
     {
+        resetInProgress.release();
+
         throw;
-    }
-    catch(...)
-    {
-        fParseInProgress = false;
-        throw;
-    }
+    }    
 }
 
 void AbstractDOMParser::parse(const char* const systemId)
@@ -538,21 +549,19 @@
     if (fParseInProgress)
         ThrowXMLwithMemMgr(IOException, XMLExcepts::Gen_ParseInProgress, fMemoryManager);
 
+    ResetInProgressType     resetInProgress(this, &AbstractDOMParser::resetInProgress);
+
     try
     {
         fParseInProgress = true;
         fScanner->scanDocument(systemId);
-        fParseInProgress = false;
     }
     catch(const OutOfMemoryException&)
     {
+        resetInProgress.release();
+
         throw;
-    }
-    catch(...)
-    {
-        fParseInProgress = false;
-        throw;
-    }
+    }    
 }
 
 

Modified: xerces/c/trunk/src/xercesc/parsers/AbstractDOMParser.hpp
URL: http://svn.apache.org/viewcvs/xerces/c/trunk/src/xercesc/parsers/AbstractDOMParser.hpp?rev=180348&r1=180347&r2=180348&view=diff
==============================================================================
--- xerces/c/trunk/src/xercesc/parsers/AbstractDOMParser.hpp (original)
+++ xerces/c/trunk/src/xercesc/parsers/AbstractDOMParser.hpp Mon Jun  6 10:41:39 2005
@@ -1648,6 +1648,7 @@
     // -----------------------------------------------------------------------
     void initialize();
     void cleanUp();
+    void resetInProgress();
 
     // -----------------------------------------------------------------------
     //  Unimplemented constructors and operators

Modified: xerces/c/trunk/src/xercesc/parsers/DOMBuilderImpl.cpp
URL: http://svn.apache.org/viewcvs/xerces/c/trunk/src/xercesc/parsers/DOMBuilderImpl.cpp?rev=180348&r1=180347&r2=180348&view=diff
==============================================================================
--- xerces/c/trunk/src/xercesc/parsers/DOMBuilderImpl.cpp (original)
+++ xerces/c/trunk/src/xercesc/parsers/DOMBuilderImpl.cpp Mon Jun  6 10:41:39 2005
@@ -605,6 +605,8 @@
     return 0;
 }
 
+typedef JanitorMemFunCall<DOMBuilderImpl>    ResetParseType;
+
 // ---------------------------------------------------------------------------
 //  DOMBuilderImpl: Grammar preparsing methods
 // ---------------------------------------------------------------------------
@@ -616,7 +618,10 @@
     if (getParseInProgress())
         ThrowXMLwithMemMgr(IOException, XMLExcepts::Gen_ParseInProgress, fMemoryManager);
 
+    ResetParseType  resetParse(this, &DOMBuilderImpl::resetParse);
+
 	Grammar* grammar = 0;
+
     try
     {
         setParseInProgress(true);
@@ -628,20 +633,11 @@
         DOMDocument* doc = adoptDocument();
         if (doc)
             doc->release();
-        
-        if (grammarType == Grammar::DTDGrammarType) 
-            getScanner()->setDocTypeHandler(this);
-        setParseInProgress(false);
     }
     catch(const OutOfMemoryException&)
     {
-        throw;
-    }
-    catch(...)
-    {
-        if (grammarType == Grammar::DTDGrammarType) 
-            getScanner()->setDocTypeHandler(this);
-        setParseInProgress(false);
+        resetParse.release();
+
         throw;
     }
 
@@ -656,7 +652,10 @@
     if (getParseInProgress())
         ThrowXMLwithMemMgr(IOException, XMLExcepts::Gen_ParseInProgress, fMemoryManager);
 
-    Grammar* grammar = 0;
+    ResetParseType  resetParse(this, &DOMBuilderImpl::resetParse);
+
+	Grammar* grammar = 0;
+
     try
     {
         setParseInProgress(true);
@@ -668,20 +667,11 @@
         DOMDocument* doc = adoptDocument();
         if (doc)
             doc->release();
-
-        if (grammarType == Grammar::DTDGrammarType) 
-            getScanner()->setDocTypeHandler(this);
-        setParseInProgress(false);
     }
     catch(const OutOfMemoryException&)
     {
-        throw;
-    }
-    catch(...)
-    {
-        if (grammarType == Grammar::DTDGrammarType) 
-            getScanner()->setDocTypeHandler(this);
-        setParseInProgress(false);
+        resetParse.release();
+
         throw;
     }
 
@@ -696,7 +686,10 @@
     if (getParseInProgress())
         ThrowXMLwithMemMgr(IOException, XMLExcepts::Gen_ParseInProgress, fMemoryManager);
 
+    ResetParseType  resetParse(this, &DOMBuilderImpl::resetParse);
+
     Grammar* grammar = 0;
+
     try
     {
         Wrapper4DOMInputSource isWrapper((DOMInputSource*) &source, false, getMemoryManager());
@@ -710,20 +703,11 @@
         DOMDocument* doc = adoptDocument();
         if (doc)
             doc->release();
-
-        if (grammarType == Grammar::DTDGrammarType) 
-            getScanner()->setDocTypeHandler(this);
-        setParseInProgress(false);
     }
     catch(const OutOfMemoryException&)
     {
-        throw;
-    }
-    catch(...)
-    {
-        if (grammarType == Grammar::DTDGrammarType) 
-            getScanner()->setDocTypeHandler(this);
-        setParseInProgress(false);
+        resetParse.release();
+
         throw;
     }
 
@@ -733,6 +717,16 @@
 void DOMBuilderImpl::resetCachedGrammarPool()
 {
     getGrammarResolver()->resetCachedGrammar();
+}
+
+void DOMBuilderImpl::resetParse()
+{
+    if (getScanner()->getDocTypeHandler() == 0)
+    {
+        getScanner()->setDocTypeHandler(this);
+    }
+
+    setParseInProgress(false);
 }
 
 Grammar* DOMBuilderImpl::getGrammar(const XMLCh* const nameSpaceKey) const

Modified: xerces/c/trunk/src/xercesc/parsers/DOMBuilderImpl.hpp
URL: http://svn.apache.org/viewcvs/xerces/c/trunk/src/xercesc/parsers/DOMBuilderImpl.hpp?rev=180348&r1=180347&r2=180348&view=diff
==============================================================================
--- xerces/c/trunk/src/xercesc/parsers/DOMBuilderImpl.hpp (original)
+++ xerces/c/trunk/src/xercesc/parsers/DOMBuilderImpl.hpp Mon Jun  6 10:41:39 2005
@@ -837,6 +837,11 @@
 
 private :
     // -----------------------------------------------------------------------
+    //  Initialize/Cleanup methods
+    // -----------------------------------------------------------------------
+    void resetParse();
+
+    // -----------------------------------------------------------------------
     //  Private data members
     //
     //  fEntityResolver

Modified: xerces/c/trunk/src/xercesc/parsers/SAX2XMLReaderImpl.cpp
URL: http://svn.apache.org/viewcvs/xerces/c/trunk/src/xercesc/parsers/SAX2XMLReaderImpl.cpp?rev=180348&r1=180347&r2=180348&view=diff
==============================================================================
--- xerces/c/trunk/src/xercesc/parsers/SAX2XMLReaderImpl.cpp (original)
+++ xerces/c/trunk/src/xercesc/parsers/SAX2XMLReaderImpl.cpp Mon Jun  6 10:41:39 2005
@@ -332,6 +332,12 @@
     chOpenSquare, chLatin_d, chLatin_t, chLatin_d, chCloseSquare, chNull
 };
 
+
+
+typedef JanitorMemFunCall<SAX2XMLReaderImpl>    CleanupType;
+typedef JanitorMemFunCall<SAX2XMLReaderImpl>    ResetInProgressType;
+
+
 SAX2XMLReaderImpl::SAX2XMLReaderImpl(MemoryManager* const  manager
                                    , XMLGrammarPool* const gramPool):
 
@@ -363,19 +369,22 @@
     , fMemoryManager(manager)
     , fGrammarPool(gramPool)
 {
+    CleanupType cleanup(this, &SAX2XMLReaderImpl::cleanUp);
+
     try
     {
         initialize();
     }
     catch(const OutOfMemoryException&)
     {
+        // Don't cleanup when out of memory, since executing the
+        // code can cause problems.
+        cleanup.release();
+
         throw;
     }
-    catch(...)
-    {
-        cleanUp();
-        throw;
-    }
+
+    cleanup.release();
 }
 
 SAX2XMLReaderImpl::~SAX2XMLReaderImpl()
@@ -664,19 +673,17 @@
     if (fParseInProgress)
         ThrowXMLwithMemMgr(IOException, XMLExcepts::Gen_ParseInProgress, fMemoryManager);
 
+    ResetInProgressType     resetInProgress(this, &SAX2XMLReaderImpl::resetInProgress);
+
     try
     {
         fParseInProgress = true;
         fScanner->scanDocument(source);
-        fParseInProgress = false;
     }
     catch(const OutOfMemoryException&)
     {
-        throw;
-    }
-    catch (...)
-    {
-        fParseInProgress = false;
+        resetInProgress.release();
+
         throw;
     }
 }
@@ -687,19 +694,17 @@
     if (fParseInProgress)
         ThrowXMLwithMemMgr(IOException, XMLExcepts::Gen_ParseInProgress, fMemoryManager);
 
+    ResetInProgressType     resetInProgress(this, &SAX2XMLReaderImpl::resetInProgress);
+
     try
     {
         fParseInProgress = true;
         fScanner->scanDocument(systemId);
-        fParseInProgress = false;
     }
     catch(const OutOfMemoryException&)
     {
-        throw;
-    }
-    catch (...)
-    {
-        fParseInProgress = false;
+        resetInProgress.release();
+
         throw;
     }
 }
@@ -710,6 +715,8 @@
     if (fParseInProgress)
         ThrowXMLwithMemMgr(IOException, XMLExcepts::Gen_ParseInProgress, fMemoryManager);
 
+    ResetInProgressType     resetInProgress(this, &SAX2XMLReaderImpl::resetInProgress);
+
     try
     {
         fParseInProgress = true;
@@ -718,11 +725,8 @@
     }
     catch(const OutOfMemoryException&)
     {
-        throw;
-    }
-    catch (...)
-    {
-        fParseInProgress = false;
+        resetInProgress.release();
+
         throw;
     }
 }
@@ -1746,20 +1750,18 @@
     if (fParseInProgress)
         ThrowXMLwithMemMgr(IOException, XMLExcepts::Gen_ParseInProgress, fMemoryManager);
 
+    ResetInProgressType     resetInProgress(this, &SAX2XMLReaderImpl::resetInProgress);
+
     Grammar* grammar = 0;
     try
     {
         fParseInProgress = true;
         grammar = fScanner->loadGrammar(systemId, grammarType, toCache);
-        fParseInProgress = false;
     }
     catch(const OutOfMemoryException&)
     {
-        throw;
-    }
-    catch(...)
-    {
-        fParseInProgress = false;
+        resetInProgress.release();
+
         throw;
     }
 
@@ -1774,20 +1776,18 @@
     if (fParseInProgress)
         ThrowXMLwithMemMgr(IOException, XMLExcepts::Gen_ParseInProgress, fMemoryManager);
 
+    ResetInProgressType     resetInProgress(this, &SAX2XMLReaderImpl::resetInProgress);
+
     Grammar* grammar = 0;
     try
     {
         fParseInProgress = true;
         grammar = fScanner->loadGrammar(systemId, grammarType, toCache);
-        fParseInProgress = false;
     }
     catch(const OutOfMemoryException&)
     {
-        throw;
-    }
-    catch(...)
-    {
-        fParseInProgress = false;
+        resetInProgress.release();
+
         throw;
     }
 
@@ -1802,24 +1802,27 @@
     if (fParseInProgress)
         ThrowXMLwithMemMgr(IOException, XMLExcepts::Gen_ParseInProgress, fMemoryManager);
 
+    ResetInProgressType     resetInProgress(this, &SAX2XMLReaderImpl::resetInProgress);
+
     Grammar* grammar = 0;
     try
     {
         fParseInProgress = true;
         grammar = fScanner->loadGrammar(source, grammarType, toCache);
-        fParseInProgress = false;
     }
     catch(const OutOfMemoryException&)
     {
-        throw;
-    }
-    catch(...)
-    {
-        fParseInProgress = false;
+        resetInProgress.release();
+
         throw;
     }
 
     return grammar;
+}
+
+void SAX2XMLReaderImpl::resetInProgress()
+{
+    fParseInProgress = false;
 }
 
 void SAX2XMLReaderImpl::resetCachedGrammarPool()

Modified: xerces/c/trunk/src/xercesc/parsers/SAX2XMLReaderImpl.hpp
URL: http://svn.apache.org/viewcvs/xerces/c/trunk/src/xercesc/parsers/SAX2XMLReaderImpl.hpp?rev=180348&r1=180347&r2=180348&view=diff
==============================================================================
--- xerces/c/trunk/src/xercesc/parsers/SAX2XMLReaderImpl.hpp (original)
+++ xerces/c/trunk/src/xercesc/parsers/SAX2XMLReaderImpl.hpp Mon Jun  6 10:41:39 2005
@@ -1775,6 +1775,7 @@
     // -----------------------------------------------------------------------
     void initialize();
     void cleanUp();
+    void resetInProgress();
 
     // -----------------------------------------------------------------------
     //  Private data members

Modified: xerces/c/trunk/src/xercesc/parsers/SAXParser.cpp
URL: http://svn.apache.org/viewcvs/xerces/c/trunk/src/xercesc/parsers/SAXParser.cpp?rev=180348&r1=180347&r2=180348&view=diff
==============================================================================
--- xerces/c/trunk/src/xercesc/parsers/SAXParser.cpp (original)
+++ xerces/c/trunk/src/xercesc/parsers/SAXParser.cpp Mon Jun  6 10:41:39 2005
@@ -281,6 +281,12 @@
 // ---------------------------------------------------------------------------
 //  SAXParser: Constructors and Destructor
 // ---------------------------------------------------------------------------
+
+
+typedef JanitorMemFunCall<SAXParser>    CleanupType;
+typedef JanitorMemFunCall<SAXParser>    ResetInProgressType;
+
+
 SAXParser::SAXParser( XMLValidator* const   valToAdopt
                     , MemoryManager* const  manager
                     , XMLGrammarPool* const gramPool):
@@ -304,19 +310,22 @@
     , fGrammarPool(gramPool)
     , fElemQNameBuf(1023, manager)
 {
+    CleanupType cleanup(this, &SAXParser::cleanUp);
+
     try
     {
         initialize();
     }
     catch(const OutOfMemoryException&)
     {
+        // Don't cleanup when out of memory, since executing the
+        // code can cause problems.
+        cleanup.release();
+
         throw;
     }
-    catch(...)
-    {
-        cleanUp();
-        throw;
-    }
+
+    cleanup.release();
 }
 
 
@@ -763,19 +772,17 @@
     if (fParseInProgress)
         ThrowXMLwithMemMgr(IOException, XMLExcepts::Gen_ParseInProgress, fMemoryManager);
 
+    ResetInProgressType     resetInProgress(this, &SAXParser::resetInProgress);
+
     try
     {
         fParseInProgress = true;
         fScanner->scanDocument(source);
-        fParseInProgress = false;
     }
     catch(const OutOfMemoryException&)
     {
-        throw;
-    }
-    catch (...)
-    {
-        fParseInProgress = false;
+        resetInProgress.release();
+
         throw;
     }
 }
@@ -786,19 +793,17 @@
     if (fParseInProgress)
         ThrowXMLwithMemMgr(IOException, XMLExcepts::Gen_ParseInProgress, fMemoryManager);
 
+    ResetInProgressType     resetInProgress(this, &SAXParser::resetInProgress);
+
     try
     {
         fParseInProgress = true;
         fScanner->scanDocument(systemId);
-        fParseInProgress = false;
     }
     catch(const OutOfMemoryException&)
     {
-        throw;
-    }
-    catch (...)
-    {
-        fParseInProgress = false;
+        resetInProgress.release();
+
         throw;
     }
 }
@@ -809,19 +814,17 @@
     if (fParseInProgress)
         ThrowXMLwithMemMgr(IOException, XMLExcepts::Gen_ParseInProgress, fMemoryManager);
 
+    ResetInProgressType     resetInProgress(this, &SAXParser::resetInProgress);
+
     try
     {
         fParseInProgress = true;
         fScanner->scanDocument(systemId);
-        fParseInProgress = false;
     }
     catch(const OutOfMemoryException&)
     {
-        throw;
-    }
-    catch (...)
-    {
-        fParseInProgress = false;
+        resetInProgress.release();
+
         throw;
     }
 }
@@ -1510,20 +1513,18 @@
     if (fParseInProgress)
         ThrowXMLwithMemMgr(IOException, XMLExcepts::Gen_ParseInProgress, fMemoryManager);
 
+    ResetInProgressType     resetInProgress(this, &SAXParser::resetInProgress);
+
     Grammar* grammar = 0;
     try
     {
         fParseInProgress = true;
         grammar = fScanner->loadGrammar(systemId, grammarType, toCache);
-        fParseInProgress = false;
     }
     catch(const OutOfMemoryException&)
     {
-        throw;
-    }
-    catch(...)
-    {
-        fParseInProgress = false;
+        resetInProgress.release();
+
         throw;
     }
 
@@ -1538,20 +1539,18 @@
     if (fParseInProgress)
         ThrowXMLwithMemMgr(IOException, XMLExcepts::Gen_ParseInProgress, fMemoryManager);
 
+    ResetInProgressType     resetInProgress(this, &SAXParser::resetInProgress);
+
     Grammar* grammar = 0;
     try
     {
         fParseInProgress = true;
         grammar = fScanner->loadGrammar(systemId, grammarType, toCache);
-        fParseInProgress = false;
     }
     catch(const OutOfMemoryException&)
     {
-        throw;
-    }
-    catch(...)
-    {
-        fParseInProgress = false;
+        resetInProgress.release();
+
         throw;
     }
 
@@ -1566,24 +1565,27 @@
     if (fParseInProgress)
         ThrowXMLwithMemMgr(IOException, XMLExcepts::Gen_ParseInProgress, fMemoryManager);
 
+    ResetInProgressType     resetInProgress(this, &SAXParser::resetInProgress);
+
     Grammar* grammar = 0;
     try
     {
         fParseInProgress = true;
         grammar = fScanner->loadGrammar(source, grammarType, toCache);
-        fParseInProgress = false;
     }
     catch(const OutOfMemoryException&)
     {
-        throw;
-    }
-    catch(...)
-    {
-        fParseInProgress = false;
+        resetInProgress.release();
+
         throw;
     }
 
     return grammar;
+}
+
+void SAXParser::resetInProgress()
+{
+    fParseInProgress = false;
 }
 
 void SAXParser::resetCachedGrammarPool()

Modified: xerces/c/trunk/src/xercesc/parsers/SAXParser.hpp
URL: http://svn.apache.org/viewcvs/xerces/c/trunk/src/xercesc/parsers/SAXParser.hpp?rev=180348&r1=180347&r2=180348&view=diff
==============================================================================
--- xerces/c/trunk/src/xercesc/parsers/SAXParser.hpp (original)
+++ xerces/c/trunk/src/xercesc/parsers/SAXParser.hpp Mon Jun  6 10:41:39 2005
@@ -2251,6 +2251,7 @@
     // -----------------------------------------------------------------------
     void initialize();
     void cleanUp();
+    void resetInProgress();
 
     // -----------------------------------------------------------------------
     //  Private data members

Modified: xerces/c/trunk/src/xercesc/parsers/XercesDOMParser.cpp
URL: http://svn.apache.org/viewcvs/xerces/c/trunk/src/xercesc/parsers/XercesDOMParser.cpp?rev=180348&r1=180347&r2=180348&view=diff
==============================================================================
--- xerces/c/trunk/src/xercesc/parsers/XercesDOMParser.cpp (original)
+++ xerces/c/trunk/src/xercesc/parsers/XercesDOMParser.cpp Mon Jun  6 10:41:39 2005
@@ -251,6 +251,8 @@
     return 0;
 }
 
+typedef JanitorMemFunCall<XercesDOMParser>  ResetParseType;
+
 // ---------------------------------------------------------------------------
 //  XercesDOMParser: Grammar preparsing methods
 // ---------------------------------------------------------------------------
@@ -262,26 +264,21 @@
     if (getParseInProgress())
         ThrowXMLwithMemMgr(IOException, XMLExcepts::Gen_ParseInProgress, fMemoryManager);
 
+    ResetParseType  resetParse(this, &XercesDOMParser::resetParse);
+
     Grammar* grammar = 0;
+
     try
     {
         setParseInProgress(true);
         if (grammarType == Grammar::DTDGrammarType) 
             getScanner()->setDocTypeHandler(0);
         grammar = getScanner()->loadGrammar(systemId, grammarType, toCache);
-        if (grammarType == Grammar::DTDGrammarType) 
-            getScanner()->setDocTypeHandler(this);
-        setParseInProgress(false);
     }
     catch(const OutOfMemoryException&)
     {
-        throw;
-    }
-    catch(...)
-    {
-        if (grammarType == Grammar::DTDGrammarType) 
-            getScanner()->setDocTypeHandler(this);        
-        setParseInProgress(false);
+        resetParse.release();
+
         throw;
     }
 
@@ -296,26 +293,21 @@
     if (getParseInProgress())
         ThrowXMLwithMemMgr(IOException, XMLExcepts::Gen_ParseInProgress, fMemoryManager);
 
+    ResetParseType  resetParse(this, &XercesDOMParser::resetParse);
+
     Grammar* grammar = 0;
+
     try
     {
         setParseInProgress(true);
         if (grammarType == Grammar::DTDGrammarType) 
             getScanner()->setDocTypeHandler(0);
         grammar = getScanner()->loadGrammar(systemId, grammarType, toCache);
-        if (grammarType == Grammar::DTDGrammarType) 
-            getScanner()->setDocTypeHandler(this);
-        setParseInProgress(false);
     }
     catch(const OutOfMemoryException&)
     {
-        throw;
-    }
-    catch(...)
-    {
-        if (grammarType == Grammar::DTDGrammarType) 
-            getScanner()->setDocTypeHandler(this);        
-        setParseInProgress(false);
+        resetParse.release();
+
         throw;
     }
 
@@ -330,7 +322,10 @@
     if (getParseInProgress())
         ThrowXMLwithMemMgr(IOException, XMLExcepts::Gen_ParseInProgress, fMemoryManager);
 
-   Grammar* grammar = 0;
+    ResetParseType  resetParse(this, &XercesDOMParser::resetParse);
+
+    Grammar* grammar = 0;
+
     try
     {
         setParseInProgress(true);
@@ -343,17 +338,22 @@
     }
     catch(const OutOfMemoryException&)
     {
+        resetParse.release();
+
         throw;
     }
-    catch(...)
+
+    return grammar;
+}
+
+void XercesDOMParser::resetParse()
+{
+    if (getScanner()->getDocTypeHandler() == 0)
     {
-        if (grammarType == Grammar::DTDGrammarType) 
-            getScanner()->setDocTypeHandler(this);
-        setParseInProgress(false);
-        throw;
+        getScanner()->setDocTypeHandler(this);
     }
 
-    return grammar;
+    setParseInProgress(false);
 }
 
 void XercesDOMParser::resetCachedGrammarPool()

Modified: xerces/c/trunk/src/xercesc/parsers/XercesDOMParser.hpp
URL: http://svn.apache.org/viewcvs/xerces/c/trunk/src/xercesc/parsers/XercesDOMParser.hpp?rev=180348&r1=180347&r2=180348&view=diff
==============================================================================
--- xerces/c/trunk/src/xercesc/parsers/XercesDOMParser.hpp (original)
+++ xerces/c/trunk/src/xercesc/parsers/XercesDOMParser.hpp Mon Jun  6 10:41:39 2005
@@ -640,6 +640,11 @@
 
 private :
     // -----------------------------------------------------------------------
+    //  Initialize/Cleanup methods
+    // -----------------------------------------------------------------------
+    void resetParse();
+
+    // -----------------------------------------------------------------------
     //  Unimplemented constructors and operators
     // -----------------------------------------------------------------------
     XercesDOMParser(const XercesDOMParser&);

Modified: xerces/c/trunk/src/xercesc/util/Janitor.c
URL: http://svn.apache.org/viewcvs/xerces/c/trunk/src/xercesc/util/Janitor.c?rev=180348&r1=180347&r2=180348&view=diff
==============================================================================
--- xerces/c/trunk/src/xercesc/util/Janitor.c (original)
+++ xerces/c/trunk/src/xercesc/util/Janitor.c Mon Jun  6 10:41:39 2005
@@ -231,5 +231,38 @@
     fMemoryManager = manager;
 }
 
-XERCES_CPP_NAMESPACE_END
 
+
+template <class T>
+JanitorMemFunCall<T>::JanitorMemFunCall(
+            T*      object,
+            MFPT    toCall) :
+    fObject(object),
+    fToCall(toCall)
+{
+}
+
+
+template <class T>
+JanitorMemFunCall<T>::~JanitorMemFunCall()
+{
+    if (fObject != 0 && fToCall != 0)
+    {
+        (fObject->*fToCall)();
+    }
+}
+
+
+// ---------------------------------------------------------------------------
+//  Janitor: Public, non-virtual methods
+// ---------------------------------------------------------------------------
+template <class T> void
+JanitorMemFunCall<T>::release()
+{
+    fObject = 0;
+    fToCall = 0;
+}
+
+
+
+XERCES_CPP_NAMESPACE_END

Modified: xerces/c/trunk/src/xercesc/util/Janitor.hpp
URL: http://svn.apache.org/viewcvs/xerces/c/trunk/src/xercesc/util/Janitor.hpp?rev=180348&r1=180347&r2=180348&view=diff
==============================================================================
--- xerces/c/trunk/src/xercesc/util/Janitor.hpp (original)
+++ xerces/c/trunk/src/xercesc/util/Janitor.hpp Mon Jun  6 10:41:39 2005
@@ -159,6 +159,50 @@
     MemoryManager* fMemoryManager;
 };
 
+
+
+template <class T> class JanitorMemFunCall
+{
+public  :
+
+    typedef void (T::*MFPT) ();
+
+    // -----------------------------------------------------------------------
+    //  Constructors and Destructor
+    // -----------------------------------------------------------------------
+    JanitorMemFunCall(
+        T*      object,
+        MFPT    toCall);
+
+    ~JanitorMemFunCall();
+
+    // -----------------------------------------------------------------------
+    //  Public, non-virtual methods
+    // -----------------------------------------------------------------------
+	void release();
+
+private :
+    // -----------------------------------------------------------------------
+    //  Unimplemented constructors and operators
+    // -----------------------------------------------------------------------
+    JanitorMemFunCall();
+    JanitorMemFunCall(const JanitorMemFunCall<T>&);
+    JanitorMemFunCall<T>& operator=(const JanitorMemFunCall<T>&);
+
+    // -----------------------------------------------------------------------
+    //  Private data members
+    //
+    //  fObject
+    //      This is the pointer to the object for which we will call the
+    //      member function when this object is destroyed.
+    // -----------------------------------------------------------------------
+    T*      fObject;
+    MFPT    fToCall;
+};
+
+
+
+
 XERCES_CPP_NAMESPACE_END
 
 #if !defined(XERCES_TMPLSINC)

Modified: xerces/c/trunk/src/xercesc/util/QName.cpp
URL: http://svn.apache.org/viewcvs/xerces/c/trunk/src/xercesc/util/QName.cpp?rev=180348&r1=180347&r2=180348&view=diff
==============================================================================
--- xerces/c/trunk/src/xercesc/util/QName.cpp (original)
+++ xerces/c/trunk/src/xercesc/util/QName.cpp Mon Jun  6 10:41:39 2005
@@ -90,6 +90,7 @@
  *
  */
 
+#include <xercesc/util/Janitor.hpp>
 #include <xercesc/util/QName.hpp>
 #include <xercesc/util/OutOfMemoryException.hpp>
 
@@ -110,6 +111,8 @@
 {
 }
 
+typedef JanitorMemFunCall<QName>    CleanupType;
+
 QName::QName( const XMLCh* const   prefix
             , const XMLCh* const   localPart
             , const unsigned int   uriId
@@ -123,6 +126,8 @@
 ,fRawName(0)
 ,fMemoryManager(manager)
 {
+    CleanupType cleanup(this, &QName::cleanUp);
+
     try
     {
         //
@@ -133,12 +138,12 @@
     }
     catch(const OutOfMemoryException&)
     {
+        cleanup.release();
+
         throw;
     }
-    catch(...)
-    {
-        cleanUp();
-    }
+
+    cleanup.release();
 }
 
 QName::QName( const XMLCh* const rawName
@@ -153,6 +158,8 @@
 ,fRawName(0)
 ,fMemoryManager(manager)
 {
+    CleanupType cleanup(this, &QName::cleanUp);
+
     try
     {
         //
@@ -163,12 +170,12 @@
     }
     catch(const OutOfMemoryException&)
     {
+        cleanup.release();
+
         throw;
     }
-    catch(...)
-    {
-        cleanUp();
-    }
+
+    cleanup.release();
 }
 
 QName::~QName()

Modified: xerces/c/trunk/src/xercesc/util/XMLAbstractDoubleFloat.cpp
URL: http://svn.apache.org/viewcvs/xerces/c/trunk/src/xercesc/util/XMLAbstractDoubleFloat.cpp?rev=180348&r1=180347&r2=180348&view=diff
==============================================================================
--- xerces/c/trunk/src/xercesc/util/XMLAbstractDoubleFloat.cpp (original)
+++ xerces/c/trunk/src/xercesc/util/XMLAbstractDoubleFloat.cpp Mon Jun  6 10:41:39 2005
@@ -612,10 +612,8 @@
 
         janRetBuffer.release();
         return retBuffer;
-
-    } //try
-
-    catch (...)
+    }
+    catch (const NumberFormatException&)
     {
         return 0;
     }

Modified: xerces/c/trunk/src/xercesc/util/XMLBigDecimal.cpp
URL: http://svn.apache.org/viewcvs/xerces/c/trunk/src/xercesc/util/XMLBigDecimal.cpp?rev=180348&r1=180347&r2=180348&view=diff
==============================================================================
--- xerces/c/trunk/src/xercesc/util/XMLBigDecimal.cpp (original)
+++ xerces/c/trunk/src/xercesc/util/XMLBigDecimal.cpp Mon Jun  6 10:41:39 2005
@@ -137,6 +137,8 @@
 //
 **/
 
+typedef JanitorMemFunCall<XMLBigDecimal>    CleanupType;
+
 XMLBigDecimal::XMLBigDecimal(const XMLCh* const strValue,
                              MemoryManager* const manager)
 : fSign(0)
@@ -150,6 +152,8 @@
     if ((!strValue) || (!*strValue))
         ThrowXMLwithMemMgr(NumberFormatException, XMLExcepts::XMLNUM_emptyString, fMemoryManager);
 
+    CleanupType cleanup(this, &XMLBigDecimal::cleanUp);
+
     try
     {
         fRawDataLen = XMLString::stringLen(strValue);
@@ -164,13 +168,12 @@
     }
     catch(const OutOfMemoryException&)
     {
+        cleanup.release();
+
         throw;
     }
-    catch(...)
-    {
-        cleanUp();
-        throw;
-    }
+
+    cleanup.release();
 }
 
 XMLBigDecimal::~XMLBigDecimal()
@@ -219,14 +222,19 @@
                                                ,       MemoryManager* const memMgr)
 {
 
-    try 
-    {
-
     XMLCh* retBuf = (XMLCh*) memMgr->allocate( (XMLString::stringLen(rawData)+1) * sizeof(XMLCh));
     ArrayJanitor<XMLCh> janName(retBuf, memMgr);
     int   sign, totalDigits, fractDigits;
 
-    XMLBigDecimal::parseDecimal(rawData, retBuf, sign, totalDigits, fractDigits, memMgr);
+    try
+    {
+        parseDecimal(rawData, retBuf, sign, totalDigits, fractDigits, memMgr);
+    }
+    catch (const NumberFormatException&)
+    {
+        return 0;
+    }
+
 
     //Extra space reserved in case strLen is zero
     int    strLen = XMLString::stringLen(retBuf);
@@ -278,13 +286,6 @@
     }
             
     return retBuffer;
-
-    }//try
-    catch (...)
-    {
-        return 0;
-    }
-
 }
 
 void  XMLBigDecimal::parseDecimal(const XMLCh* const toParse

Modified: xerces/c/trunk/src/xercesc/util/XMLBigInteger.cpp
URL: http://svn.apache.org/viewcvs/xerces/c/trunk/src/xercesc/util/XMLBigInteger.cpp?rev=180348&r1=180347&r2=180348&view=diff
==============================================================================
--- xerces/c/trunk/src/xercesc/util/XMLBigInteger.cpp (original)
+++ xerces/c/trunk/src/xercesc/util/XMLBigInteger.cpp Mon Jun  6 10:41:39 2005
@@ -134,9 +134,8 @@
         jan.release();
         return retBuf;
 
-    }//
-
-    catch (...)
+    }
+    catch (const NumberFormatException&)
     {
         return 0;
     }



---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@xerces.apache.org
For additional commands, e-mail: commits-help@xerces.apache.org