You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@xerces.apache.org by ca...@apache.org on 2003/12/31 16:40:01 UTC

cvs commit: xml-xerces/c/src/xercesc/internal IGXMLScanner.cpp XMLReader.cpp XMLScanner.cpp XMLScanner.hpp

cargilld    2003/12/31 07:40:01

  Modified:    c/src/xercesc/validators/DTD DTDScanner.cpp
               c/src/xercesc/internal IGXMLScanner.cpp XMLReader.cpp
                        XMLScanner.cpp XMLScanner.hpp
  Log:
  Release memory when an error is encountered.
  
  Revision  Changes    Path
  1.31      +30 -3     xml-xerces/c/src/xercesc/validators/DTD/DTDScanner.cpp
  
  Index: DTDScanner.cpp
  ===================================================================
  RCS file: /home/cvs/xml-xerces/c/src/xercesc/validators/DTD/DTDScanner.cpp,v
  retrieving revision 1.30
  retrieving revision 1.31
  diff -u -r1.30 -r1.31
  --- DTDScanner.cpp	17 Dec 2003 00:18:40 -0000	1.30
  +++ DTDScanner.cpp	31 Dec 2003 15:40:00 -0000	1.31
  @@ -56,6 +56,9 @@
   
   /*
    * $Log$
  + * Revision 1.31  2003/12/31 15:40:00  cargilld
  + * Release memory when an error is encountered.
  + *
    * Revision 1.30  2003/12/17 00:18:40  cargilld
    * Update to memory management so that the static memory manager (one used to call Initialize) is only for static data.
    *
  @@ -1322,7 +1325,13 @@
           if (tmpNode != curNode)
           {
               if (gotSpaces)
  +            {
  +                if (fScanner->emitErrorWillThrowException(XMLErrs::UnexpectedWhitespace))
  +                {
  +                    delete tmpNode;
  +                }
                   fScanner->emitError(XMLErrs::UnexpectedWhitespace);
  +            }
               fReaderMgr->getNextChar();
               curNode = tmpNode;
           }
  @@ -1447,7 +1456,15 @@
                       curReader = fReaderMgr->getCurrentReaderNum();
   
                       // Recurse to handle this new guy
  -                    ContentSpecNode* subNode = scanChildren(elemDecl, bufToUse);
  +                    ContentSpecNode* subNode;
  +                    try {
  +                        subNode = scanChildren(elemDecl, bufToUse);
  +                    }
  +                    catch (const XMLErrs::Codes)
  +                    {
  +                        delete headNode;
  +                        throw;
  +                    }
   
                       // If it failed, we are done, clean up here and return failure
                       if (!subNode)
  @@ -1542,6 +1559,7 @@
                else
               {
                   // Cannot be valid
  +                delete headNode;  // emitError may do a throw so need to clean-up first
                   if (opCh == chComma)
                   {
                       fScanner->emitError(XMLErrs::ExpectedChoiceOrCloseParen);
  @@ -1553,8 +1571,7 @@
                           XMLErrs::ExpectedSeqOrCloseParen
                           , elemDecl.getFullName()
                       );
  -                }
  -                delete headNode;
  +                }                
                   return 0;
               }
           }
  @@ -3421,6 +3438,10 @@
               //  Tell them they can't have reps in mixed model, but eat
               //  it and keep going if we are allowed to.
               //
  +            if (fScanner->emitErrorWillThrowException(XMLErrs::NoRepInMixed))
  +            {
  +                delete headNode;
  +            }
               fScanner->emitError(XMLErrs::NoRepInMixed);
           }
            else if (fReaderMgr->skippedSpace())
  @@ -3446,7 +3467,13 @@
                       starSkipped = false;
   
                       if (starRequired)
  +                    {
  +                        if (fScanner->emitErrorWillThrowException(XMLErrs::UnterminatedContentModel))
  +                        {
  +                            delete headNode;
  +                        }
                           fScanner->emitError(XMLErrs::ExpectedAsterisk);
  +                    }
                   }
   
                   //
  
  
  
  1.57      +9 -2      xml-xerces/c/src/xercesc/internal/IGXMLScanner.cpp
  
  Index: IGXMLScanner.cpp
  ===================================================================
  RCS file: /home/cvs/xml-xerces/c/src/xercesc/internal/IGXMLScanner.cpp,v
  retrieving revision 1.56
  retrieving revision 1.57
  diff -u -r1.56 -r1.57
  --- IGXMLScanner.cpp	30 Dec 2003 17:50:52 -0000	1.56
  +++ IGXMLScanner.cpp	31 Dec 2003 15:40:00 -0000	1.57
  @@ -1371,7 +1371,14 @@
           // this will break getRootElemId on DTDGrammar when
           // cached grammars are in use, but 
           // why would one use this anyway???
  -        ((DTDGrammar*)fGrammar)->setRootElemId(fGrammar->putElemDecl(rootDecl));
  +        try {
  +            ((DTDGrammar*)fGrammar)->setRootElemId(fGrammar->putElemDecl(rootDecl));
  +        }
  +        catch(const XMLException&)
  +        {
  +            delete rootDecl;
  +            throw;
  +        }
       } else
       {
           // attach this to the undeclared element pool so that it gets deleted
  
  
  
  1.18      +11 -1     xml-xerces/c/src/xercesc/internal/XMLReader.cpp
  
  Index: XMLReader.cpp
  ===================================================================
  RCS file: /home/cvs/xml-xerces/c/src/xercesc/internal/XMLReader.cpp,v
  retrieving revision 1.17
  retrieving revision 1.18
  diff -u -r1.17 -r1.18
  --- XMLReader.cpp	17 Dec 2003 00:18:34 -0000	1.17
  +++ XMLReader.cpp	31 Dec 2003 15:40:00 -0000	1.18
  @@ -70,6 +70,7 @@
   #include <xercesc/util/TransService.hpp>
   #include <xercesc/util/XMLEBCDICTranscoder.hpp>
   #include <xercesc/util/XMLString.hpp>
  +#include <xercesc/util/Janitor.hpp>
   
   
   XERCES_CPP_NAMESPACE_BEGIN
  @@ -1321,6 +1322,9 @@
                   {
                       fCharsAvail = 0;
                       fRawBufIndex = 0;
  +                    fMemoryManager->deallocate(fPublicId);
  +                    fMemoryManager->deallocate(fEncodingStr);
  +                    ArrayJanitor<XMLCh> janValue(fSystemId, fMemoryManager);
                       ThrowXMLwithMemMgr1
                       (
                           TranscodingException
  @@ -1397,6 +1401,9 @@
                   {
                       fCharsAvail = 0;
                       fRawBufIndex = 0;
  +                    fMemoryManager->deallocate(fPublicId);
  +                    fMemoryManager->deallocate(fEncodingStr);
  +                    ArrayJanitor<XMLCh> janValue(fSystemId, fMemoryManager);
                       ThrowXMLwithMemMgr1
                       (
                           TranscodingException
  @@ -1514,6 +1521,9 @@
   
           default :
               // It should never be anything else here
  +            fMemoryManager->deallocate(fPublicId);
  +            fMemoryManager->deallocate(fEncodingStr);                    
  +            fMemoryManager->deallocate(fSystemId);
               ThrowXMLwithMemMgr(TranscodingException, XMLExcepts::Reader_BadAutoEncoding, fMemoryManager);
               break;
       }
  
  
  
  1.59      +11 -4     xml-xerces/c/src/xercesc/internal/XMLScanner.cpp
  
  Index: XMLScanner.cpp
  ===================================================================
  RCS file: /home/cvs/xml-xerces/c/src/xercesc/internal/XMLScanner.cpp,v
  retrieving revision 1.58
  retrieving revision 1.59
  diff -u -r1.58 -r1.59
  --- XMLScanner.cpp	24 Dec 2003 15:24:13 -0000	1.58
  +++ XMLScanner.cpp	31 Dec 2003 15:40:00 -0000	1.59
  @@ -782,6 +782,13 @@
   //  These methods are called whenever the scanner wants to emit an error.
   //  It handles getting the message loaded, doing token replacement, etc...
   //  and then calling the error handler, if its installed.
  +bool XMLScanner::emitErrorWillThrowException(const XMLErrs::Codes toEmit)
  +{
  +    if (XMLErrs::isFatal(toEmit) && fExitOnFirstFatal && !fInException)
  +        return true;
  +    return false;
  +}
  +
   void XMLScanner::emitError(const XMLErrs::Codes toEmit)
   {
       // Bump the error count if it is not a warning
  @@ -820,7 +827,7 @@
       }
   
       // Bail out if its fatal an we are to give up on the first fatal error
  -    if (XMLErrs::isFatal(toEmit) && fExitOnFirstFatal && !fInException)
  +    if (emitErrorWillThrowException(toEmit))
           throw toEmit;
   }
   
  @@ -867,7 +874,7 @@
       }
   
       // Bail out if its fatal an we are to give up on the first fatal error
  -    if (XMLErrs::isFatal(toEmit) && fExitOnFirstFatal && !fInException)
  +    if (emitErrorWillThrowException(toEmit))
           throw toEmit;
   }
   
  @@ -914,7 +921,7 @@
       }
   
       // Bail out if its fatal an we are to give up on the first fatal error
  -    if (XMLErrs::isFatal(toEmit) && fExitOnFirstFatal && !fInException)
  +    if (emitErrorWillThrowException(toEmit))
           throw toEmit;
   }
   
  
  
  
  1.32      +4 -0      xml-xerces/c/src/xercesc/internal/XMLScanner.hpp
  
  Index: XMLScanner.hpp
  ===================================================================
  RCS file: /home/cvs/xml-xerces/c/src/xercesc/internal/XMLScanner.hpp,v
  retrieving revision 1.31
  retrieving revision 1.32
  diff -u -r1.31 -r1.32
  --- XMLScanner.hpp	28 Nov 2003 21:18:32 -0000	1.31
  +++ XMLScanner.hpp	31 Dec 2003 15:40:00 -0000	1.32
  @@ -56,6 +56,9 @@
   
   /*
    * $Log$
  + * Revision 1.32  2003/12/31 15:40:00  cargilld
  + * Release memory when an error is encountered.
  + *
    * Revision 1.31  2003/11/28 21:18:32  knoaman
    * Make use of canonical representation in PSVIElement
    *
  @@ -429,6 +432,7 @@
       // -----------------------------------------------------------------------
       //  Error emitter methods
       // -----------------------------------------------------------------------
  +    bool emitErrorWillThrowException(const XMLErrs::Codes toEmit);
       void emitError(const XMLErrs::Codes toEmit);
       void emitError
       (
  
  
  

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