diff options
author | David Tardon <dtardon@redhat.com> | 2015-07-14 15:52:55 +0200 |
---|---|---|
committer | David Tardon <dtardon@redhat.com> | 2015-07-14 15:52:55 +0200 |
commit | a69da92be817325e36e7ee5dcdb6c9d3146dad5a (patch) | |
tree | 6a1b6d059354ce2ae679f9b4375e94317c710975 /src | |
parent | e8e0700a9ac0c87e058678f64ae39d3eef4a11fd (diff) |
avoid leak of xmlTextReader
Change-Id: If82d2b1a81a742a65d9826513e3d83b779602b7b
Diffstat (limited to 'src')
-rw-r--r-- | src/lib/VSDXParser.cpp | 25 |
1 files changed, 12 insertions, 13 deletions
diff --git a/src/lib/VSDXParser.cpp b/src/lib/VSDXParser.cpp index d2be71a..d65308e 100644 --- a/src/lib/VSDXParser.cpp +++ b/src/lib/VSDXParser.cpp @@ -299,21 +299,21 @@ void libvisio::VSDXParser::processXmlDocument(librevenge::RVNGInputStream *input m_rels = &rels; - xmlTextReaderPtr reader = xmlReaderForStream(input, 0, 0, XML_PARSE_NOBLANKS|XML_PARSE_NOENT|XML_PARSE_NONET); + boost::shared_ptr<xmlTextReader> reader(xmlReaderForStream(input, 0, 0, XML_PARSE_NOBLANKS|XML_PARSE_NOENT|XML_PARSE_NONET), xmlFreeTextReader); if (!reader) return; - int ret = xmlTextReaderRead(reader); + int ret = xmlTextReaderRead(reader.get()); while (1 == ret) { - int tokenId = VSDXMLTokenMap::getTokenId(xmlTextReaderConstName(reader)); - int tokenType = xmlTextReaderNodeType(reader); + int tokenId = VSDXMLTokenMap::getTokenId(xmlTextReaderConstName(reader.get())); + int tokenType = xmlTextReaderNodeType(reader.get()); switch (tokenId) { case XML_REL: if (XML_READER_TYPE_ELEMENT == tokenType) { - xmlChar *id = xmlTextReaderGetAttribute(reader, BAD_CAST("r:id")); + xmlChar *id = xmlTextReaderGetAttribute(reader.get(), BAD_CAST("r:id")); if (id) { const VSDXRelationship *rel = rels.getRelationshipById((char *)id); @@ -322,34 +322,33 @@ void libvisio::VSDXParser::processXmlDocument(librevenge::RVNGInputStream *input std::string type = rel->getType(); if (type == "http://schemas.microsoft.com/visio/2010/relationships/master") { - m_currentDepth += xmlTextReaderDepth(reader); + m_currentDepth += xmlTextReaderDepth(reader.get()); parseMaster(m_input, rel->getTarget().c_str()); - m_currentDepth -= xmlTextReaderDepth(reader); + m_currentDepth -= xmlTextReaderDepth(reader.get()); } else if (type == "http://schemas.microsoft.com/visio/2010/relationships/page") { - m_currentDepth += xmlTextReaderDepth(reader); + m_currentDepth += xmlTextReaderDepth(reader.get()); parsePage(m_input, rel->getTarget().c_str()); - m_currentDepth -= xmlTextReaderDepth(reader); + m_currentDepth -= xmlTextReaderDepth(reader.get()); } else if (type == "http://schemas.openxmlformats.org/officeDocument/2006/relationships/image") { extractBinaryData(m_input, rel->getTarget().c_str()); } else - processXmlNode(reader); + processXmlNode(reader.get()); } xmlFree(id); } } break; default: - processXmlNode(reader); + processXmlNode(reader.get()); break; } - ret = xmlTextReaderRead(reader); + ret = xmlTextReaderRead(reader.get()); } - xmlFreeTextReader(reader); } void libvisio::VSDXParser::processXmlNode(xmlTextReaderPtr reader) |