From 1bdf6d8ba878c1fe1d779824be70001fc0bebd2c Mon Sep 17 00:00:00 2001 From: Even Rouault Date: Fri, 27 Aug 2021 01:33:27 +0200 Subject: [PATCH] InMemMsgLoader::loadMsg(): fix memory leak when transcoding fails. Seen with the IconvGNU transcoder when parsing " --- .../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 cda103226..6971fde96 100644 --- a/src/xercesc/util/MsgLoaders/InMemory/InMemMsgLoader.cpp +++ b/src/xercesc/util/MsgLoaders/InMemory/InMemMsgLoader.cpp @@ -25,6 +25,7 @@ // --------------------------------------------------------------------------- #include #include +#include #include #include #include @@ -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); -- 2.17.1