diff --git a/src/xercesc/framework/XMLAttr.cpp b/src/xercesc/framework/XMLAttr.cpp
index 987317c34c1142a80f26097365713abc4c9d1ed5..0a6663e005dbccb19ba580d65b36f84c9006f3bb 100644
--- a/src/xercesc/framework/XMLAttr.cpp
+++ b/src/xercesc/framework/XMLAttr.cpp
@@ -157,6 +157,7 @@ void XMLAttr::setValue(const XMLCh* const newValue)
     if (!fValueBufSz || (newLen > fValueBufSz))
     {
         fMemoryManager->deallocate(fValue); //delete [] fValue;
+        fValue = 0;
         fValueBufSz = newLen + 8;
         fValue = (XMLCh*) fMemoryManager->allocate((fValueBufSz+1) * sizeof(XMLCh)); //new XMLCh[fValueBufSz + 1];
     }
diff --git a/src/xercesc/framework/psvi/PSVIAttributeList.cpp b/src/xercesc/framework/psvi/PSVIAttributeList.cpp
index f31af1a4c961c2c00bd3a39fd9f1881ae2072ad8..545cd73e18d1e54c045ce128859ec36382405c23 100644
--- a/src/xercesc/framework/psvi/PSVIAttributeList.cpp
+++ b/src/xercesc/framework/psvi/PSVIAttributeList.cpp
@@ -26,6 +26,9 @@ XERCES_CPP_NAMESPACE_BEGIN
 
 PSVIAttributeList::PSVIAttributeList( MemoryManager* const manager ):  
         fMemoryManager(manager)
+        , fAttrList(0)
+        , fAttrNameList(0)
+        , fAttrNSList(0)
         , fAttrPos(0)
 {
     fAttrList= new (fMemoryManager) RefVectorOf<PSVIAttribute> (10, true, fMemoryManager);
diff --git a/src/xercesc/internal/XMLGrammarPoolImpl.cpp b/src/xercesc/internal/XMLGrammarPoolImpl.cpp
index 2df98bd648ead595f62ceba2c1d5b9dff8191c7d..0f1a35813921a299cdfb2c4dbd69fe291b06cb17 100644
--- a/src/xercesc/internal/XMLGrammarPoolImpl.cpp
+++ b/src/xercesc/internal/XMLGrammarPoolImpl.cpp
@@ -38,6 +38,7 @@ XERCES_CPP_NAMESPACE_BEGIN
 void XMLGrammarPoolImpl::createXSModel()
 {
     delete fXSModel;
+    fXSModel = 0;
     fXSModel = new (getMemoryManager()) XSModel(this, getMemoryManager());
     fXSModelIsValid = true; 
 }
diff --git a/src/xercesc/internal/XMLReader.cpp b/src/xercesc/internal/XMLReader.cpp
index 845fb52f6a042ecff3034b9111264ac7e80d4bba..8dafd48f14d36abad75ed85a0738c6337df6345c 100644
--- a/src/xercesc/internal/XMLReader.cpp
+++ b/src/xercesc/internal/XMLReader.cpp
@@ -1269,10 +1269,12 @@ bool XMLReader::setEncoding(const XMLCh* const newEncoding)
 
         if (fEncoding == XMLRecognizer::UTF_16L) {
             fMemoryManager->deallocate(fEncodingStr);
+            fEncodingStr = 0;
             fEncodingStr = XMLString::replicate(XMLUni::fgUTF16LEncodingString, fMemoryManager);
         }
         else {
             fMemoryManager->deallocate(fEncodingStr);
+            fEncodingStr = 0;
             fEncodingStr = XMLString::replicate(XMLUni::fgUTF16BEncodingString, fMemoryManager);
         }
     }
@@ -1294,11 +1296,13 @@ bool XMLReader::setEncoding(const XMLCh* const newEncoding)
         if (fEncoding == XMLRecognizer::UCS_4L) {
 
             fMemoryManager->deallocate(fEncodingStr);
+            fEncodingStr = 0;
             fEncodingStr = XMLString::replicate(XMLUni::fgUCS4LEncodingString, fMemoryManager);
         }
         else {
 
             fMemoryManager->deallocate(fEncodingStr);
+            fEncodingStr = 0;
             fEncodingStr = XMLString::replicate(XMLUni::fgUCS4BEncodingString, fMemoryManager);
         }
     }
diff --git a/src/xercesc/internal/XMLScanner.cpp b/src/xercesc/internal/XMLScanner.cpp
index 9982c6f9ea3e12a8e387b3a5637a502fef830329..7b07013875747b61509fb900ff3e9ef09c3ae0cb 100644
--- a/src/xercesc/internal/XMLScanner.cpp
+++ b/src/xercesc/internal/XMLScanner.cpp
@@ -772,9 +772,9 @@ void XMLScanner::commonInit()
 
     // create initial, 64-element, fUIntPool
     fUIntPool = (unsigned int **)fMemoryManager->allocate(sizeof(unsigned int *) *fUIntPoolRowTotal);
+    memset(fUIntPool, 0, sizeof(unsigned int *) * fUIntPoolRowTotal);
     fUIntPool[0] = (unsigned int *)fMemoryManager->allocate(sizeof(unsigned int) << 6);
-    memset(fUIntPool[0], 0, sizeof(unsigned int) << 6);
-    fUIntPool[1] = 0;
+    memset(fUIntPool[0], 0, sizeof(unsigned int) << 6);    
 
     // Register self as handler for XMLBufferFull events on the CDATA buffer
     fCDataBuf.setFullHandler(this, fBufferSize);
@@ -794,11 +794,14 @@ void XMLScanner::cleanUp()
     fMemoryManager->deallocate(fExternalSchemaLocation);//delete [] fExternalSchemaLocation;
     fMemoryManager->deallocate(fExternalNoNamespaceSchemaLocation);//delete [] fExternalNoNamespaceSchemaLocation;
     // delete fUIntPool
-    for (unsigned int i=0; i<=fUIntPoolRow; i++)
-    {
-        fMemoryManager->deallocate(fUIntPool[i]);
+    if (fUIntPool)
+    {    
+        for (unsigned int i=0; i<=fUIntPoolRow; i++)
+        {
+            fMemoryManager->deallocate(fUIntPool[i]);
+        }
+        fMemoryManager->deallocate(fUIntPool);
     }
-    fMemoryManager->deallocate(fUIntPool);
 }
 
 void XMLScanner::initValidator(XMLValidator* theValidator) {
diff --git a/src/xercesc/util/KVStringPair.hpp b/src/xercesc/util/KVStringPair.hpp
index f54443e8a5d67e16e5d6dc7363d02435707c51ca..9720d2f0ef07cea54530e76e819636f2a9fca236 100644
--- a/src/xercesc/util/KVStringPair.hpp
+++ b/src/xercesc/util/KVStringPair.hpp
@@ -178,6 +178,7 @@ inline void KVStringPair::setKey(  const XMLCh* const newKey
     if (newKeyLength >= fKeyAllocSize)
     {
         fMemoryManager->deallocate(fKey); //delete [] fKey;
+        fKey = 0;
         fKeyAllocSize = newKeyLength + 1;
         fKey = (XMLCh*) fMemoryManager->allocate(fKeyAllocSize * sizeof(XMLCh)); //new XMLCh[fKeyAllocSize];
     }
@@ -191,6 +192,7 @@ inline void KVStringPair::setValue(  const XMLCh* const newValue
     if (newValueLength >= fValueAllocSize)
     {
         fMemoryManager->deallocate(fValue); //delete [] fValue;
+        fValue = 0;
         fValueAllocSize = newValueLength + 1;
         fValue = (XMLCh*) fMemoryManager->allocate(fValueAllocSize * sizeof(XMLCh)); //new XMLCh[fValueAllocSize];
     }
diff --git a/src/xercesc/util/NameIdPool.c b/src/xercesc/util/NameIdPool.c
index 17d035e3e77aecfb081ed057a7c75916fb026b24..51de78097aa31cb6aed4c77b10e41b280712440b 100644
--- a/src/xercesc/util/NameIdPool.c
+++ b/src/xercesc/util/NameIdPool.c
@@ -73,8 +73,7 @@ NameIdPool<TElem>::NameIdPool( const unsigned int hashModulus
     (
         fHashModulus * sizeof(NameIdPoolBucketElem<TElem>*)
     ); //new NameIdPoolBucketElem<TElem>*[fHashModulus];
-    for (unsigned int index = 0; index < fHashModulus; index++)
-        fBucketList[index] = 0;
+    memset(fBucketList, 0, sizeof(fBucketList[0]) * fHashModulus);
 
     //
     //  Allocate the initial id pointers array. We don't have to zero them
diff --git a/src/xercesc/util/QName.cpp b/src/xercesc/util/QName.cpp
index a1f6f85f4a4b998292721b19d90e5f20c98c4ee4..0fd1e57879b83144a764d8e94a939c44a418d01f 100644
--- a/src/xercesc/util/QName.cpp
+++ b/src/xercesc/util/QName.cpp
@@ -180,6 +180,7 @@ const XMLCh* QName::getRawName() const
             {
                 fMemoryManager->deallocate(fRawName); //delete [] fRawName;
 
+                ((QName*)this)->fRawName = 0;
                 // We have to cast off the const'ness to do this
                 ((QName*)this)->fRawNameBufSz = neededLen;
                 ((QName*)this)->fRawName = (XMLCh*) fMemoryManager->allocate
@@ -234,7 +235,8 @@ XMLCh* QName::getRawName()
             if (!fRawName || (neededLen > fRawNameBufSz))
             {
                 fMemoryManager->deallocate(fRawName); //delete [] fRawName;
-
+                
+                fRawName = 0;
                 // We have to cast off the const'ness to do this
                 ((QName*)this)->fRawNameBufSz = neededLen;
                 ((QName*)this)->fRawName = (XMLCh*) fMemoryManager->allocate
@@ -292,6 +294,7 @@ void QName::setName(const XMLCh* const    rawName
         if (!fRawNameBufSz || (newLen > fRawNameBufSz))
         {
             fMemoryManager->deallocate(fRawName); //delete [] fRawName;
+            fRawName = 0;
             fRawNameBufSz = newLen + 8;
             fRawName = (XMLCh*) fMemoryManager->allocate
             (
@@ -325,6 +328,7 @@ void QName::setPrefix(const XMLCh* prefix)
     if (!fPrefixBufSz || (newLen > fPrefixBufSz))
     {
         fMemoryManager->deallocate(fPrefix); //delete [] fPrefix;
+        fPrefix = 0;
         fPrefixBufSz = newLen + 8;
         fPrefix = (XMLCh*) fMemoryManager->allocate
         (
@@ -339,6 +343,7 @@ void QName::setNPrefix(const XMLCh* prefix, const unsigned int newLen)
     if (!fPrefixBufSz || (newLen > fPrefixBufSz))
     {
         fMemoryManager->deallocate(fPrefix); //delete [] fPrefix;
+        fPrefix = 0;
         fPrefixBufSz = newLen + 8;
         fPrefix = (XMLCh*) fMemoryManager->allocate
         (
@@ -357,6 +362,7 @@ void QName::setLocalPart(const XMLCh* localPart)
     if (!fLocalPartBufSz || (newLen > fLocalPartBufSz))
     {
         fMemoryManager->deallocate(fLocalPart); //delete [] fLocalPart;
+        fLocalPart = 0;
         fLocalPartBufSz = newLen + 8;
         fLocalPart = (XMLCh*) fMemoryManager->allocate
         (
@@ -371,6 +377,7 @@ void QName::setNLocalPart(const XMLCh* localPart, const unsigned int newLen)
     if (!fLocalPartBufSz || (newLen > fLocalPartBufSz))
     {
         fMemoryManager->deallocate(fLocalPart); //delete [] fLocalPart;
+        fLocalPart = 0;
         fLocalPartBufSz = newLen + 8;
         fLocalPart = (XMLCh*) fMemoryManager->allocate
         (
diff --git a/src/xercesc/util/RefHash2KeysTableOf.c b/src/xercesc/util/RefHash2KeysTableOf.c
index 2fb6223eb7d7e2a46b86baa6b3397f37a093c7fa..666fff83259dde546937e0a91d7d6649d469a82c 100644
--- a/src/xercesc/util/RefHash2KeysTableOf.c
+++ b/src/xercesc/util/RefHash2KeysTableOf.c
@@ -97,8 +97,7 @@ void RefHash2KeysTableOf<TVal>::initialize(const unsigned int modulus)
     (
         fHashModulus * sizeof(RefHash2KeysTableBucketElem<TVal>*)
     ); //new RefHash2KeysTableBucketElem<TVal>*[fHashModulus];
-    for (unsigned int index = 0; index < fHashModulus; index++)
-        fBucketList[index] = 0;
+    memset(fBucketList, 0, sizeof(fBucketList[0]) * fHashModulus);
 }
 
 template <class TVal> RefHash2KeysTableOf<TVal>::~RefHash2KeysTableOf()
diff --git a/src/xercesc/util/RefHash3KeysIdPool.c b/src/xercesc/util/RefHash3KeysIdPool.c
index ac73cfa71771cd4b93d4d4d3b253ba3651977152..16109f83ba12c1c4121ef525e41404e92bf8dbb3 100644
--- a/src/xercesc/util/RefHash3KeysIdPool.c
+++ b/src/xercesc/util/RefHash3KeysIdPool.c
@@ -142,8 +142,7 @@ template <class TVal> void RefHash3KeysIdPool<TVal>::initialize(const unsigned i
     (
         fHashModulus * sizeof(RefHash3KeysTableBucketElem<TVal>*)
     ); //new RefHash3KeysTableBucketElem<TVal>*[fHashModulus];
-    for (unsigned int index = 0; index < fHashModulus; index++)
-        fBucketList[index] = 0;
+    memset(fBucketList, 0, sizeof(fBucketList[0]) * fHashModulus);
 }
 
 template <class TVal> RefHash3KeysIdPool<TVal>::~RefHash3KeysIdPool()
diff --git a/src/xercesc/util/ValueHashTableOf.c b/src/xercesc/util/ValueHashTableOf.c
index cb852025d86552d14b77b71d408f2feb8780365b..0eb74f1ecfc9afd25faed54e1cb9094ddefd1944 100644
--- a/src/xercesc/util/ValueHashTableOf.c
+++ b/src/xercesc/util/ValueHashTableOf.c
@@ -73,8 +73,7 @@ template <class TVal> void ValueHashTableOf<TVal>::initialize(const unsigned int
     (
         fHashModulus * sizeof(ValueHashTableBucketElem<TVal>*)
     ); //new ValueHashTableBucketElem<TVal>*[fHashModulus];
-    for (unsigned int index = 0; index < fHashModulus; index++)
-        fBucketList[index] = 0;
+    memset(fBucketList, 0, sizeof(fBucketList[0]) * fHashModulus);
 }
 
 template <class TVal> ValueHashTableOf<TVal>::~ValueHashTableOf()
diff --git a/src/xercesc/util/regx/StringToken.hpp b/src/xercesc/util/regx/StringToken.hpp
index 7d21c969bad79f4ac5dd2d1c6b883209261932b4..c33c16e3fac6d0ea88ef4d56b5a97c4ba93f8d8b 100644
--- a/src/xercesc/util/regx/StringToken.hpp
+++ b/src/xercesc/util/regx/StringToken.hpp
@@ -86,6 +86,7 @@ inline const XMLCh* StringToken::getString() const {
 inline void StringToken::setString(const XMLCh* const literal) {
 
 	fMemoryManager->deallocate(fString);//delete [] fString;
+    fString = 0;
 	fString = XMLString::replicate(literal, fMemoryManager);
 }
 
diff --git a/src/xercesc/validators/common/GrammarResolver.cpp b/src/xercesc/validators/common/GrammarResolver.cpp
index c25b52ccfb733a732d907601574286853342ff81..688ec4be745cd8507d8290d6a740ed230ff3993f 100644
--- a/src/xercesc/validators/common/GrammarResolver.cpp
+++ b/src/xercesc/validators/common/GrammarResolver.cpp
@@ -44,6 +44,7 @@ GrammarResolver::GrammarResolver(XMLGrammarPool* const gramPool
 ,fGrammarPool(gramPool)
 ,fXSModel(0)
 ,fGrammarPoolXSModel(0)
+,fGrammarsToAddToXSModel(0)
 {
     fGrammarBucket = new (manager) RefHashTableOf<Grammar>(29, true,  manager);
 
diff --git a/src/xercesc/validators/schema/SchemaInfo.cpp b/src/xercesc/validators/schema/SchemaInfo.cpp
index d44d645d1f488325a882a193aedda05b17c4c9e2..2b682e10df7acb3b6b7ca4150cfdac2f9b36ca16 100644
--- a/src/xercesc/validators/schema/SchemaInfo.cpp
+++ b/src/xercesc/validators/schema/SchemaInfo.cpp
@@ -65,11 +65,16 @@ SchemaInfo::SchemaInfo(const unsigned short elemAttrDefaultQualified,
     , fMemoryManager(manager)
 {
     fImportingInfoList = new (fMemoryManager) RefVectorOf<SchemaInfo>(4, false, fMemoryManager);
-    for (unsigned int i = 0; i < C_Count; i++)
-    {
-        fTopLevelComponents[i] = 0;
-        fLastTopLevelComponent[i] = 0;
-    }
+
+	memset(
+         fTopLevelComponents,
+         0,
+         sizeof(fTopLevelComponents[0]) * C_Count);    
+    memset(
+         fLastTopLevelComponent,
+         0,
+         sizeof(fLastTopLevelComponent[0]) * C_Count);    
+    
     fNonXSAttList = new (fMemoryManager) ValueVectorOf<DOMNode*>(2, fMemoryManager);
     fValidationContext = new (fMemoryManager) ValidationContextImpl(fMemoryManager);
 }
@@ -83,34 +88,18 @@ SchemaInfo::~SchemaInfo()
     if (fAdoptInclude)
         delete fIncludeInfoList;
 
-    delete fImportingInfoList;
-
-    fImportedInfoList = fIncludeInfoList = fImportingInfoList = 0;
-
+    delete fImportingInfoList;  
     delete fImportedNSList;
-    fImportedNSList = 0;
-
     delete fFailedRedefineList;
-    fFailedRedefineList = 0;
-
     delete fRecursingAnonTypes;
-    fRecursingAnonTypes = 0;
-
-    delete fRecursingTypeNames;
-    fRecursingTypeNames = 0;
+    delete fRecursingTypeNames;   
 
     for (unsigned int i = 0; i < C_Count; i++) {
-
         delete fTopLevelComponents[i];
-        fTopLevelComponents[i] = 0;
-        fLastTopLevelComponent[i] = 0;
     }
 
-    delete fNonXSAttList;
-    fNonXSAttList = 0;
-
-    delete fValidationContext;
-    fValidationContext = 0;
+    delete fNonXSAttList;  
+    delete fValidationContext;    
 }
 
 // ---------------------------------------------------------------------------
diff --git a/src/xercesc/validators/schema/TraverseSchema.cpp b/src/xercesc/validators/schema/TraverseSchema.cpp
index 0abe3fd89d2c36221bd67c60403e17853a37dec7..e0839adbeb04face04e0f1c0f44052de54a85a60 100644
--- a/src/xercesc/validators/schema/TraverseSchema.cpp
+++ b/src/xercesc/validators/schema/TraverseSchema.cpp
@@ -14,6 +14,10 @@
  * limitations under the License.
  */
 
+/*
+ * $Id$
+ */
+
 // ---------------------------------------------------------------------------
 //  Includes
 // ---------------------------------------------------------------------------
@@ -584,7 +588,7 @@ void TraverseSchema::preprocessInclude(const DOMElement* const elem) {
     // ------------------------------------------------------------------
     fLocator->setValues(fSchemaInfo->getCurrentSchemaURL(), 0,
                         ((XSDElementNSImpl*) elem)->getLineNo(),
-                        ((XSDElementNSImpl*) elem)->getColumnNo());    
+                        ((XSDElementNSImpl*) elem)->getColumnNo());      
     InputSource* srcToFill = resolveSchemaLocation(schemaLocation,
             XMLResourceIdentifier::SchemaInclude);
     Janitor<InputSource> janSrc(srcToFill);
@@ -778,9 +782,9 @@ void TraverseSchema::preprocessImport(const DOMElement* const elem) {
     // ------------------------------------------------------------------
     // Resolve schema location
     // ------------------------------------------------------------------
-	fLocator->setValues(fSchemaInfo->getCurrentSchemaURL(), 0,
+    fLocator->setValues(fSchemaInfo->getCurrentSchemaURL(), 0,
                         ((XSDElementNSImpl*) elem)->getLineNo(),
-                        ((XSDElementNSImpl*) elem)->getColumnNo());    
+                        ((XSDElementNSImpl*) elem)->getColumnNo());     
     InputSource* srcToFill = resolveSchemaLocation(schemaLocation,
             XMLResourceIdentifier::SchemaImport, nameSpace);
 
@@ -1560,10 +1564,11 @@ TraverseSchema::traverseGroupDecl(const DOMElement* const elem,
     Janitor<ContentSpecNode> specNode(0);
     XercesGroupInfo* saveGroupInfo = fCurrentGroupInfo;
 
-    Janitor<XercesGroupInfo>    newGroupInfo(new (fGrammarPoolMemoryManager) XercesGroupInfo(
+    Janitor<XercesGroupInfo>    newGroupInfoJan(new (fGrammarPoolMemoryManager) XercesGroupInfo(
         fStringPool->addOrFind(name), fTargetNSURI, fGrammarPoolMemoryManager));    
     fCurrentGroupStack->addElement(nameIndex);
-    fCurrentGroupInfo = newGroupInfo.get();    
+    XercesGroupInfo* const newGroupInfo = newGroupInfoJan.get();
+    fCurrentGroupInfo = newGroupInfo;    
 
     fCurrentScope = fScopeCount++;
     fCurrentGroupInfo->setScope(fCurrentScope);
@@ -1614,19 +1619,20 @@ TraverseSchema::traverseGroupDecl(const DOMElement* const elem,
 
     fCurrentGroupInfo->setContentSpec(specNode.release());
     fGroupRegistry->put((void*) fullName, fCurrentGroupInfo);
+    newGroupInfoJan.release();
     fCurrentGroupInfo = saveGroupInfo;
     fCurrentScope = saveScope;
 
     // Store Annotation
     if (!janAnnot.isDataNull()) {
-        fSchemaGrammar->putAnnotation(newGroupInfo.get(), janAnnot.release());        
+        fSchemaGrammar->putAnnotation(newGroupInfo, janAnnot.release());        
     }
 
     if (fFullConstraintChecking) {
 
         XSDLocator* aLocator = new (fGrammarPoolMemoryManager) XSDLocator();
 
-        newGroupInfo.get()->setLocator(aLocator);        
+        newGroupInfo->setLocator(aLocator);        
         aLocator->setValues(fStringPool->getValueForId(fStringPool->addOrFind(fSchemaInfo->getCurrentSchemaURL())),
                             0, ((XSDElementNSImpl*) elem)->getLineNo(),
                             ((XSDElementNSImpl*) elem)->getColumnNo());
@@ -1647,7 +1653,7 @@ TraverseSchema::traverseGroupDecl(const DOMElement* const elem,
                 XercesGroupInfo* baseGroup = fGroupRegistry->get(fBuffer.getRawBuffer());
                 if (baseGroup)
                 {
-                    newGroupInfo.get()->setBaseGroup(baseGroup);                    
+                    newGroupInfo->setBaseGroup(baseGroup);                    
                 }
                 else
                 {
@@ -1659,7 +1665,7 @@ TraverseSchema::traverseGroupDecl(const DOMElement* const elem,
 
                     if (groupElem != 0) {
                         baseGroup = traverseGroupDecl(groupElem);
-                        newGroupInfo.get()->setBaseGroup(baseGroup);                        
+                        newGroupInfo->setBaseGroup(baseGroup);                        
                         fSchemaInfo = saveInfo;
                     }
                     else
@@ -1672,7 +1678,7 @@ TraverseSchema::traverseGroupDecl(const DOMElement* const elem,
         }
     }
 
-    return newGroupInfo.release();    
+    return newGroupInfo;    
 }
 
 
@@ -1787,10 +1793,10 @@ TraverseSchema::traverseAttributeGroupDecl(const DOMElement* const elem,
 
         // Pop declaration
         fDeclStack->removeElementAt(fDeclStack->size() - 1);
-
-        // Restore old attGroupInfo
+       
+        fAttGroupRegistry->put((void*) fStringPool->getValueForId(fStringPool->addOrFind(name)), janAttGroupInfo.get());
+        // Restore old attGroupInfo   
         attGroupInfo = janAttGroupInfo.release();
-        fAttGroupRegistry->put((void*) fStringPool->getValueForId(fStringPool->addOrFind(name)), attGroupInfo);
         fCurrentAttGroupInfo = saveAttGroupInfo;
 
         // Check Attribute Derivation Restriction OK
@@ -1981,7 +1987,7 @@ TraverseSchema::traverseAny(const DOMElement* const elem) {
                                          , fSchemaGrammar->getValidationContext()
                                          , fMemoryManager);
                     }
-                    catch(const XMLException& excep) {
+                    catch(const XMLException& excep) {                        
                         reportSchemaError(elem, excep);
                     }
                     uriIndex = fURIStringPool->addOrFind(tokenElem);
@@ -2022,7 +2028,8 @@ TraverseSchema::traverseAny(const DOMElement* const elem) {
                     , fGrammarPoolMemoryManager
                 );
                 secondNode.release();
-                secondNode.reset(newNode);                
+                secondNode.reset(newNode); 
+                firstNode.release();
             }
         }
         firstNode.release();
@@ -6024,7 +6031,8 @@ void TraverseSchema::processComplexContent(const DOMElement* const ctElem,
                                            const bool isMixed,
                                            const bool isBaseAnyType) {
     
-    Janitor<ContentSpecNode>    specNode(0);
+    Janitor<ContentSpecNode>    specNodeJan(0);
+    ContentSpecNode* specNode = specNodeJan.get();
     const DOMElement* attrNode = 0;
     int                 typeDerivedBy = typeInfo->getDerivedBy();
     ComplexTypeInfo*    baseTypeInfo = typeInfo->getBaseComplexTypeInfo();
@@ -6071,14 +6079,14 @@ void TraverseSchema::processComplexContent(const DOMElement* const ctElem,
 
             if (grpInfo) {
 
-                specNode.reset(grpInfo->getContentSpec());
+                ContentSpecNode* const groupSpecNode = grpInfo->getContentSpec();
 
-                if (specNode.get()) {
+                if (groupSpecNode) {
 
-                    int contentContext = specNode.get()->hasAllContent() ? Group_Ref_With_All : Not_All_Context;
-                    ContentSpecNode* tempSpecNode = specNode.release();
-                    specNode.reset(new (fGrammarPoolMemoryManager) ContentSpecNode(*tempSpecNode));
-                    checkMinMax(specNode.get(), childElem, contentContext);
+                    int contentContext = groupSpecNode->hasAllContent() ? Group_Ref_With_All : Not_All_Context;
+                    specNodeJan.reset(new (fGrammarPoolMemoryManager) ContentSpecNode(*groupSpecNode));
+                    specNode = specNodeJan.get();
+                    checkMinMax(specNode, childElem, contentContext);
                 }
             }
 
@@ -6087,20 +6095,23 @@ void TraverseSchema::processComplexContent(const DOMElement* const ctElem,
         }
         else if (XMLString::equals(childName, SchemaSymbols::fgELT_SEQUENCE)) {
 
-            specNode.reset(traverseChoiceSequence(childElem, ContentSpecNode::Sequence));
-            checkMinMax(specNode.get(), childElem);
+            specNodeJan.reset(traverseChoiceSequence(childElem, ContentSpecNode::Sequence));
+            specNode = specNodeJan.get();
+            checkMinMax(specNode, childElem);
             attrNode = XUtil::getNextSiblingElement(childElem);
         }
         else if (XMLString::equals(childName, SchemaSymbols::fgELT_CHOICE)) {
 
-            specNode.reset(traverseChoiceSequence(childElem, ContentSpecNode::Choice));
-            checkMinMax(specNode.get(), childElem);
+            specNodeJan.reset(traverseChoiceSequence(childElem, ContentSpecNode::Choice));
+            specNode = specNodeJan.get();
+            checkMinMax(specNode, childElem);
             attrNode = XUtil::getNextSiblingElement(childElem);
         }
         else if (XMLString::equals(childName, SchemaSymbols::fgELT_ALL)) {
 
-            specNode.reset(traverseAll(childElem));
-            checkMinMax(specNode.get(), childElem, All_Group);
+            specNodeJan.reset(traverseAll(childElem));
+            specNode = specNodeJan.get();
+            checkMinMax(specNode, childElem, All_Group);
             attrNode = XUtil::getNextSiblingElement(childElem);
         }
         else if (isAttrOrAttrGroup(childElem)) {
@@ -6113,8 +6124,9 @@ void TraverseSchema::processComplexContent(const DOMElement* const ctElem,
         }
     }
 
-    typeInfo->setContentSpec(specNode.get());
+    typeInfo->setContentSpec(specNode);
     typeInfo->setAdoptContentSpec(true);
+    specNodeJan.release();
 
     // -----------------------------------------------------------------------
     // Merge in information from base, if it exists
@@ -6141,17 +6153,19 @@ void TraverseSchema::processComplexContent(const DOMElement* const ctElem,
 
             // Compose the final content model by concatenating the base and
             // the current in sequence
-            if (!specNode.get()) {
+            if (!specNode) {
 
                 if (baseSpecNode) {
-                    specNode.reset(new (fGrammarPoolMemoryManager) ContentSpecNode(*baseSpecNode));
-                    typeInfo->setContentSpec(specNode.get());
+                    specNodeJan.reset(new (fGrammarPoolMemoryManager) ContentSpecNode(*baseSpecNode));
+                    specNode = specNodeJan.get();
+                    typeInfo->setContentSpec(specNode);
                     typeInfo->setAdoptContentSpec(true);
+                    specNodeJan.release();
                 }
             }
             else if (baseSpecNode) {
 
-                if (specNode.get()->hasAllContent() || baseSpecNode->hasAllContent()) {
+                if (specNode->hasAllContent() || baseSpecNode->hasAllContent()) {
 
                     reportSchemaError(ctElem, XMLUni::fgXMLErrDomain, XMLErrs::NotAllContent);
                     throw TraverseSchema::InvalidComplexTypeInfo; // REVISIT - should we continue
@@ -6172,7 +6186,7 @@ void TraverseSchema::processComplexContent(const DOMElement* const ctElem,
                     (
                         ContentSpecNode::ModelGroupSequence
                         , new (fGrammarPoolMemoryManager) ContentSpecNode(*baseSpecNode)
-                        , specNode.get()
+                        , specNode
                         , true
                         , true
                         , fGrammarPoolMemoryManager
@@ -6207,7 +6221,7 @@ void TraverseSchema::processComplexContent(const DOMElement* const ctElem,
         anySpecNode->setMinOccurs(0);
         anySpecNode->setMaxOccurs(SchemaSymbols::XSD_UNBOUNDED);
 
-        if (!specNode.get()) {
+        if (!specNode) {
             typeInfo->setContentSpec(anySpecNode);
             typeInfo->setDerivedBy(typeDerivedBy);
         }
@@ -6220,7 +6234,7 @@ void TraverseSchema::processComplexContent(const DOMElement* const ctElem,
                 (
                     ContentSpecNode::ModelGroupSequence
                     , anySpecNode
-                    , specNode.get()
+                    , specNode
                     , true
                     , true
                     , fGrammarPoolMemoryManager
@@ -6239,7 +6253,7 @@ void TraverseSchema::processComplexContent(const DOMElement* const ctElem,
     }
     else if (isMixed) {
 
-        if (specNode.get() != 0) {
+        if (specNode != 0) {
             typeInfo->setContentType(SchemaElementDecl::Mixed_Complex);
         }
         else {
@@ -6285,8 +6299,7 @@ void TraverseSchema::processComplexContent(const DOMElement* const ctElem,
     }
     else if (baseTypeInfo != 0 || isBaseAnyType) {
         processAttributes(ctElem, 0, typeInfo, isBaseAnyType);
-    }
-    specNode.release();
+    }   
 }
 
 
@@ -7936,7 +7949,7 @@ bool TraverseSchema::openRedefinedSchema(const DOMElement* const redefineElem) {
     // ------------------------------------------------------------------
     fLocator->setValues(fSchemaInfo->getCurrentSchemaURL(), 0,
                         ((XSDElementNSImpl*) redefineElem)->getLineNo(),
-                        ((XSDElementNSImpl*) redefineElem)->getColumnNo());    
+                        ((XSDElementNSImpl*) redefineElem)->getColumnNo());      
     InputSource*         srcToFill = resolveSchemaLocation(schemaLocation,
                                         XMLResourceIdentifier::SchemaRedefine);
     Janitor<InputSource> janSrc(srcToFill);
@@ -8029,9 +8042,9 @@ bool TraverseSchema::openRedefinedSchema(const DOMElement* const redefineElem) {
 
         traverseSchemaHeader(root);
         fSchemaInfoList->put((void*) fSchemaInfo->getCurrentSchemaURL(), fSchemaInfo->getTargetNSURI(), fSchemaInfo);
-        redefSchemaInfo->addSchemaInfo(fSchemaInfo, SchemaInfo::INCLUDE);
-        fPreprocessedNodes->put((void*) redefineElem, fSchemaInfo);
         newSchemaInfo.release();
+        redefSchemaInfo->addSchemaInfo(fSchemaInfo, SchemaInfo::INCLUDE);
+        fPreprocessedNodes->put((void*) redefineElem, fSchemaInfo);        
     }
 
     return true;
@@ -8490,7 +8503,6 @@ void TraverseSchema::reportSchemaError(const DOMElement* const elem,
 
     fXSDErrorReporter.emitError(except, fLocator);
 }
-
 // ---------------------------------------------------------------------------
 //  TraverseSchema: Init/CleanUp methods
 // ---------------------------------------------------------------------------
@@ -8511,6 +8523,7 @@ void TraverseSchema::init() {
     (
         ENUM_ELT_SIZE * sizeof(ValueVectorOf<unsigned int>*)
     );//new ValueVectorOf<unsigned int>*[ENUM_ELT_SIZE];
+    memset(fGlobalDeclarations, 0, ENUM_ELT_SIZE * sizeof(ValueVectorOf<unsigned int>*));
     for(unsigned int i=0; i < ENUM_ELT_SIZE; i++)
         fGlobalDeclarations[i] = new (fMemoryManager) ValueVectorOf<unsigned int>(8, fMemoryManager);
 
@@ -8534,10 +8547,12 @@ void TraverseSchema::cleanUp() {
     delete fCurrentTypeNameStack;
     delete fCurrentGroupStack;
 
-    for(unsigned int i=0; i < ENUM_ELT_SIZE; i++)
-        delete fGlobalDeclarations[i];
-
-    fMemoryManager->deallocate(fGlobalDeclarations);//delete [] fGlobalDeclarations;
+    if (fGlobalDeclarations)
+    {
+        for(unsigned int i=0; i < ENUM_ELT_SIZE; i++)
+            delete fGlobalDeclarations[i];
+        fMemoryManager->deallocate(fGlobalDeclarations);//delete [] fGlobalDeclarations;
+    }    
 
     delete fNonXSAttList;
     delete fNotationRegistry;
diff --git a/src/xercesc/validators/schema/XMLSchemaDescriptionImpl.cpp b/src/xercesc/validators/schema/XMLSchemaDescriptionImpl.cpp
index 014b992e85668c17754fb7b766a9353c5b5ee92a..7b8fb5e9411c98cabf3850e5d3f27c68ecb27268 100644
--- a/src/xercesc/validators/schema/XMLSchemaDescriptionImpl.cpp
+++ b/src/xercesc/validators/schema/XMLSchemaDescriptionImpl.cpp
@@ -111,9 +111,11 @@ void XMLSchemaDescriptionImpl::setContextType(ContextType type)
 
 void XMLSchemaDescriptionImpl::setTargetNamespace(const XMLCh* const newNamespace)
 {  
-    if (fNamespace)
+    if (fNamespace) {
         XMLGrammarDescription::getMemoryManager()->deallocate((void*)fNamespace);
-                                
+        fNamespace = 0;
+    }
+    
     fNamespace = XMLString::replicate(newNamespace, XMLGrammarDescription::getMemoryManager()); 
 }
 
@@ -124,18 +126,22 @@ void XMLSchemaDescriptionImpl::setLocationHints(const XMLCh* const hint)
 
 void XMLSchemaDescriptionImpl::setTriggeringComponent(QName* const trigComponent)
 { 
-    if ( fTriggeringComponent)
+    if ( fTriggeringComponent) {
         delete fTriggeringComponent;
-                                
+        fTriggeringComponent = 0;
+    }
+    
     fTriggeringComponent = new (trigComponent->getMemoryManager()) QName(*trigComponent); 
 
 }
 
 void XMLSchemaDescriptionImpl::setEnclosingElementName(QName* const encElement)
 { 
-    if (fEnclosingElementName)
+    if (fEnclosingElementName) {
         delete fEnclosingElementName;
-                                 
+        fEnclosingElementName = 0; 
+    }
+
     fEnclosingElementName = new (encElement->getMemoryManager()) QName(*encElement); 
 
 }