From 5297f544ecb81d0a1ffd899894cec18dea645db7 Mon Sep 17 00:00:00 2001 From: Boris Kolpackov <borisk@apache.org> Date: Wed, 4 Nov 2009 15:11:14 +0000 Subject: [PATCH] Free resources if we throw from c-tors (XERCESC-1480). git-svn-id: https://svn.apache.org/repos/asf/xerces/c/trunk@832766 13f79535-47bb-0310-9956-ffa450edef68 --- src/xercesc/internal/XMLReader.cpp | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/src/xercesc/internal/XMLReader.cpp b/src/xercesc/internal/XMLReader.cpp index 9f6c5fd70..101495819 100644 --- a/src/xercesc/internal/XMLReader.cpp +++ b/src/xercesc/internal/XMLReader.cpp @@ -311,6 +311,13 @@ XMLReader::XMLReader(const XMLCh* const pubId if (!fTranscoder) { + // We are about to throw which means the d-tor won't be called. + // Clean up some memory. + // + fMemoryManager->deallocate(fPublicId); + fMemoryManager->deallocate(fSystemId); + ArrayJanitor<XMLCh> jan (fEncodingStr, fMemoryManager); + ThrowXMLwithMemMgr1 ( TranscodingException @@ -407,6 +414,13 @@ XMLReader::XMLReader(const XMLCh* const pubId if (!fTranscoder) { + // We are about to throw which means the d-tor won't be called. + // Clean up some memory. + // + fMemoryManager->deallocate(fPublicId); + fMemoryManager->deallocate(fSystemId); + ArrayJanitor<XMLCh> jan (fEncodingStr, fMemoryManager); + ThrowXMLwithMemMgr1 ( TranscodingException @@ -736,7 +750,7 @@ bool XMLReader::getNCName(XMLBuffer& toFill) { if (fCharIndex == fCharsAvail) { - // we have to copy the accepted character(s), and update the column number, + // we have to copy the accepted character(s), and update the column number, // before getting new data and losing the value of fCharIndex if((count = fCharIndex - charIndex_start)!=0) { @@ -749,7 +763,7 @@ bool XMLReader::getNCName(XMLBuffer& toFill) } // Check the current char and take it if it's a name char - if (fXMLVersion == XMLV1_1) + if (fXMLVersion == XMLV1_1) { while(fCharIndex < fCharsAvail) { -- GitLab