From b10d76c1ccda32afdfa06942436fb8f0bfcfce5b Mon Sep 17 00:00:00 2001 From: Stefan Seyfried Date: Thu, 9 Jan 2014 14:56:45 +0100 Subject: [PATCH] XML_Parser::storeAtts: don't leak in case of realloc failure Origin commit data ------------------ Branch: ni/coolstream Commit: https://github.com/neutrino-images/ni-neutrino/commit/6944d53cef9a994c02b298707fa0b30fad56c08b Author: Stefan Seyfried Date: 2014-01-09 (Thu, 09 Jan 2014) ------------------ No further description and justification available within origin commit message! ------------------ This commit was generated by Migit --- lib/xmltree/xmlparse.cpp | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/lib/xmltree/xmlparse.cpp b/lib/xmltree/xmlparse.cpp index e87d0bb1e..9f4ef239f 100644 --- a/lib/xmltree/xmlparse.cpp +++ b/lib/xmltree/xmlparse.cpp @@ -132,7 +132,8 @@ XML_Parser::XML_Parser(const XML_Char *encodingName) tagStack=0; freeTagList=0; attsSize=INIT_ATTS_SIZE; - atts=new ATTRIBUTE[attsSize]; + /* must not realloc stuff allocated with new[] */ + atts=(ATTRIBUTE *)malloc(attsSize * sizeof(ATTRIBUTE)); dataBuf=new XML_Char[INIT_DATA_BUF_SIZE]; groupSize=0; groupConnector=0; @@ -152,7 +153,7 @@ XML_Parser::XML_Parser(const XML_Char *encodingName) poolDestroy(&tempPool); poolDestroy(&temp2Pool); - if (atts) delete[] atts; + if (atts) free(atts); if (dataBuf) delete[] dataBuf; return; @@ -204,7 +205,7 @@ XML_Parser::~XML_Parser() poolDestroy(&temp2Pool); dtdDestroy(&dtd); - delete[] atts; + free(atts); free(groupConnector); free(buffer); delete[] dataBuf; @@ -1099,9 +1100,11 @@ enum XML_Error XML_Parser::storeAtts(const ENCODING *enc, const XML_Char *tagNam attsSize=n+nDefaultAtts+INIT_ATTS_SIZE; - atts=(ATTRIBUTE *) realloc((void *) atts, attsSize*sizeof(ATTRIBUTE)); + ATTRIBUTE *newatts = (ATTRIBUTE *) realloc((void *) atts, attsSize*sizeof(ATTRIBUTE)); - if (!atts) return XML_ERROR_NO_MEMORY; + if (!newatts) return XML_ERROR_NO_MEMORY; + + atts = newatts; if (n>oldAttsSize) XmlGetAttributes(enc, s, n, atts); };