[xerces-c] branch master updated: IGXMLScanner::scanDocTypeDecl(): fix memory leak on exception

[email protected]
Newsgroups gmane.text.xml.xerces-c.devel
Message-ID <[email protected]>
This is an automated email from the ASF dual-hosted git repository.

rleigh pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/xerces-c.git


The following commit(s) were added to refs/heads/master by this push:
     new 8a4c024  IGXMLScanner::scanDocTypeDecl(): fix memory leak on exception
     new ecdc077  Merge pull request #42 from rouault/fix_memleak_IGXMLScanner_scanDocTypeDecl
8a4c024 is described below

commit 8a4c024169c69ed744a570f692656522d7b51dc7
Author: Even Rouault <[email protected]>
AuthorDate: Fri Oct 29 01:20:14 2021 +0200

    IGXMLScanner::scanDocTypeDecl(): fix memory leak on exception
    
    The method can leak pubId and sysId when subsequent call to
    fReaderMgr.skipPastSpaces() throws an exception (e.g. a
    TranscodingException)
---
 src/xercesc/internal/IGXMLScanner.cpp | 11 +++++++----
 1 file changed, 7 insertions(+), 4 deletions(-)

diff --git a/src/xercesc/internal/IGXMLScanner.cpp b/src/xercesc/internal/IGXMLScanner.cpp
index 7ee8b7f..4417d44 100644
--- a/src/xercesc/internal/IGXMLScanner.cpp
+++ b/src/xercesc/internal/IGXMLScanner.cpp
@@ -1374,7 +1374,14 @@ void IGXMLScanner::scanDocTypeDecl()
         // Get copies of the ids we got
         pubId = XMLString::replicate(bbPubId.getRawBuffer(), fMemoryManager);
         sysId = XMLString::replicate(bbSysId.getRawBuffer(), fMemoryManager);
+    }
+
+    // Insure that the ids get cleaned up, if they got allocated
+    ArrayJanitor<XMLCh> janSysId(sysId, fMemoryManager);
+    ArrayJanitor<XMLCh> janPubId(pubId, fMemoryManager);
 
+    if (hasExtSubset)
+    {
         // Skip spaces and check again for the opening of an internal subset
         fReaderMgr.skipPastSpaces();
 
@@ -1384,10 +1391,6 @@ void IGXMLScanner::scanDocTypeDecl()
         }
     }
 
-    // Insure that the ids get cleaned up, if they got allocated
-    ArrayJanitor<XMLCh> janSysId(sysId, fMemoryManager);
-    ArrayJanitor<XMLCh> janPubId(pubId, fMemoryManager);
-
     //  If we have a doc type handler and advanced callbacks are enabled,
     //  call the doctype event.
     if (fDocTypeHandler)
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.