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

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

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


The following commit(s) were added to refs/heads/xerces-3.2 by this push:
     new 35a0cb4a2 IGXMLScanner::scanDocTypeDecl(): fix memory leak on exception
35a0cb4a2 is described below

commit 35a0cb4a2eaeab18988e2fada2d6547ba2fdbbf7
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 00624009d..912ec0c62 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.