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

commit cf20b46a842a05c597146ad48c2ccabfd106f98b
Author: Roger Leigh <rle...@apache.org>
AuthorDate: Thu Sep 9 08:38:15 2021 +0100

    Merge pull request #32 from rouault/fix_ossfuzz_37666
    
    XERCESC-2221: InMemMsgLoader::loadMsg(): fix memory leak when transcoding 
fails.
---
 .../util/MsgLoaders/InMemory/InMemMsgLoader.cpp    | 31 ++++++++++++++++------
 1 file changed, 23 insertions(+), 8 deletions(-)

diff --git a/src/xercesc/util/MsgLoaders/InMemory/InMemMsgLoader.cpp 
b/src/xercesc/util/MsgLoaders/InMemory/InMemMsgLoader.cpp
index d95a13685..0e0336c60 100644
--- a/src/xercesc/util/MsgLoaders/InMemory/InMemMsgLoader.cpp
+++ b/src/xercesc/util/MsgLoaders/InMemory/InMemMsgLoader.cpp
@@ -25,6 +25,7 @@
 // ---------------------------------------------------------------------------
 #include <xercesc/util/BitOps.hpp>
 #include <xercesc/util/PlatformUtils.hpp>
+#include <xercesc/util/TranscodingException.hpp>
 #include <xercesc/util/XMLMsgLoader.hpp>
 #include <xercesc/util/XMLString.hpp>
 #include <xercesc/util/XMLUni.hpp>
@@ -153,14 +154,28 @@ bool InMemMsgLoader::loadMsg(const  
XMLMsgLoader::XMLMsgId  msgToLoad
     XMLCh* tmp4 = 0;
     
     bool bRet = false;
-    if (repText1)
-        tmp1 = XMLString::transcode(repText1, manager);
-    if (repText2)
-        tmp2 = XMLString::transcode(repText2, manager);
-    if (repText3)
-        tmp3 = XMLString::transcode(repText3, manager);
-    if (repText4)
-        tmp4 = XMLString::transcode(repText4, manager);
+    try
+    {
+        if (repText1)
+            tmp1 = XMLString::transcode(repText1, manager);
+        if (repText2)
+            tmp2 = XMLString::transcode(repText2, manager);
+        if (repText3)
+            tmp3 = XMLString::transcode(repText3, manager);
+        if (repText4)
+            tmp4 = XMLString::transcode(repText4, manager);
+    }
+    catch( const TranscodingException& )
+    {
+        if (tmp1)
+            manager->deallocate(tmp1);
+        if (tmp2)
+            manager->deallocate(tmp2);
+        if (tmp3)
+            manager->deallocate(tmp3);
+        // Note: tmp4 cannot leak
+        throw;
+    }
 
     bRet = loadMsg(msgToLoad, toFill, maxChars, tmp1, tmp2, tmp3, tmp4, 
manager);
 


---------------------------------------------------------------------
To unsubscribe, e-mail: c-dev-unsubscr...@xerces.apache.org
For additional commands, e-mail: c-dev-h...@xerces.apache.org

Reply via email to