[Libreoffice-commits] libvisio.git: 2 commits - src/lib
David Tardon
dtardon at redhat.com
Tue Jan 30 09:29:04 UTC 2018
src/lib/VDXParser.cpp | 10 ++++------
src/lib/VSDXParser.cpp | 32 ++++++++++++++------------------
2 files changed, 18 insertions(+), 24 deletions(-)
New commits:
commit a10cc6f3f9412d1d1b8cd604374d6625dda60485
Author: David Tardon <dtardon at redhat.com>
Date: Tue Jan 30 10:26:36 2018 +0100
avoid more potential memory leaks
Change-Id: Ia8bb68d617687dc4f8ca37219f78f818d9fd8b57
diff --git a/src/lib/VSDXParser.cpp b/src/lib/VSDXParser.cpp
index 154b1d2..10a6081 100644
--- a/src/lib/VSDXParser.cpp
+++ b/src/lib/VSDXParser.cpp
@@ -567,41 +567,39 @@ int libvisio::VSDXParser::getElementToken(xmlTextReaderPtr reader)
if (XML_READER_TYPE_END_ELEMENT == xmlTextReaderNodeType(reader))
return tokenId;
- xmlChar *stringValue = nullptr;
+ std::unique_ptr<xmlChar, decltype(xmlFree)> stringValue(nullptr, xmlFree);
switch (tokenId)
{
case XML_CELL:
- stringValue = xmlTextReaderGetAttribute(reader, BAD_CAST("N"));
+ stringValue.reset(xmlTextReaderGetAttribute(reader, BAD_CAST("N")));
if (stringValue)
{
- tokenId = VSDXMLTokenMap::getTokenId(stringValue);
+ tokenId = VSDXMLTokenMap::getTokenId(stringValue.get());
if (tokenId == XML_TOKEN_INVALID)
{
- if (*stringValue == 'P' && !strncmp((char *)stringValue, "Position", 8))
+ if (*stringValue.get() == 'P' && !strncmp((char *)stringValue.get(), "Position", 8))
tokenId = XML_POSITION;
- else if (*stringValue == 'A' && !strncmp((char *)stringValue, "Alignment", 9))
+ else if (*stringValue.get() == 'A' && !strncmp((char *)stringValue.get(), "Alignment", 9))
tokenId = XML_ALIGNMENT;
}
}
break;
case XML_ROW:
- stringValue = xmlTextReaderGetAttribute(reader, BAD_CAST("N"));
+ stringValue.reset(xmlTextReaderGetAttribute(reader, BAD_CAST("N")));
if (!stringValue)
- stringValue = xmlTextReaderGetAttribute(reader, BAD_CAST("T"));
+ stringValue.reset(xmlTextReaderGetAttribute(reader, BAD_CAST("T")));
if (stringValue)
- tokenId = VSDXMLTokenMap::getTokenId(stringValue);
+ tokenId = VSDXMLTokenMap::getTokenId(stringValue.get());
break;
case XML_SECTION:
- stringValue = xmlTextReaderGetAttribute(reader, BAD_CAST("N"));
+ stringValue.reset(xmlTextReaderGetAttribute(reader, BAD_CAST("N")));
if (stringValue)
- tokenId = VSDXMLTokenMap::getTokenId(stringValue);
+ tokenId = VSDXMLTokenMap::getTokenId(stringValue.get());
break;
default:
break;
}
- if (stringValue)
- xmlFree(stringValue);
return tokenId;
}
@@ -694,12 +692,11 @@ void libvisio::VSDXParser::readFonts(xmlTextReaderPtr reader)
if (XML_FACENAME == tokenId && XML_READER_TYPE_ELEMENT == tokenType)
{
- xmlChar *name = xmlTextReaderGetAttribute(reader, BAD_CAST("NameU"));
+ std::unique_ptr<xmlChar, decltype(xmlFree)> name(xmlTextReaderGetAttribute(reader, BAD_CAST("NameU")), xmlFree);
if (name)
{
- librevenge::RVNGBinaryData textStream(name, xmlStrlen(name));
+ librevenge::RVNGBinaryData textStream(name.get(), xmlStrlen(name.get()));
m_fonts[idx] = VSDName(textStream, libvisio::VSD_TEXT_UTF8);
- xmlFree(name);
}
++idx;
}
@@ -1459,17 +1456,16 @@ void libvisio::VSDXParser::getBinaryData(xmlTextReaderPtr reader)
m_currentBinaryData.clear();
if (1 == ret && XML_REL == tokenId && XML_READER_TYPE_ELEMENT == tokenType)
{
- xmlChar *id = xmlTextReaderGetAttribute(reader, BAD_CAST("r:id"));
+ std::unique_ptr<xmlChar, decltype(xmlFree)> id(xmlTextReaderGetAttribute(reader, BAD_CAST("r:id")), xmlFree);
if (id)
{
- const VSDXRelationship *rel = m_rels->getRelationshipById((char *)id);
+ const VSDXRelationship *rel = m_rels->getRelationshipById((char *)id.get());
if (rel)
{
if ("http://schemas.openxmlformats.org/officeDocument/2006/relationships/image" == rel->getType()
|| "http://schemas.openxmlformats.org/officeDocument/2006/relationships/oleObject" == rel->getType())
extractBinaryData(m_input, rel->getTarget().c_str());
}
- xmlFree(id);
}
}
if (!m_shape.m_foreign)
commit edf7deeb81f044d7fde5ad1f384e61c4790fa7c2
Author: David Tardon <dtardon at redhat.com>
Date: Tue Jan 30 10:17:50 2018 +0100
ofz#5816 avoid memory leak
Change-Id: Ib23bdeb0a96590f8a22248bc5f92f85773ade58a
diff --git a/src/lib/VDXParser.cpp b/src/lib/VDXParser.cpp
index f187a13..bb7b9d3 100644
--- a/src/lib/VDXParser.cpp
+++ b/src/lib/VDXParser.cpp
@@ -810,16 +810,14 @@ void libvisio::VDXParser::readFonts(xmlTextReaderPtr reader)
if (XML_FACENAME == tokenId)
{
- xmlChar *id = xmlTextReaderGetAttribute(reader, BAD_CAST("ID"));
- xmlChar *name = xmlTextReaderGetAttribute(reader, BAD_CAST("Name"));
+ std::unique_ptr<xmlChar, decltype(xmlFree)> id(xmlTextReaderGetAttribute(reader, BAD_CAST("ID")), xmlFree);
+ std::unique_ptr<xmlChar, decltype(xmlFree)> name(xmlTextReaderGetAttribute(reader, BAD_CAST("Name")), xmlFree);
if (id && name)
{
- auto idx = (unsigned)xmlStringToLong(id);
- librevenge::RVNGBinaryData textStream(name, xmlStrlen(name));
+ auto idx = (unsigned)xmlStringToLong(id.get());
+ librevenge::RVNGBinaryData textStream(name.get(), xmlStrlen(name.get()));
m_fonts[idx] = VSDName(textStream, libvisio::VSD_TEXT_UTF8);
}
- xmlFree(name);
- xmlFree(id);
}
}
while ((XML_FACENAMES != tokenId || XML_READER_TYPE_END_ELEMENT != tokenType) && 1 == ret && (!m_watcher || !m_watcher->isError()));
More information about the Libreoffice-commits
mailing list