[Libreoffice-commits] libvisio.git: 9 commits - configure.ac src/lib
David Tardon
dtardon at redhat.com
Tue Jul 14 09:01:29 PDT 2015
configure.ac | 1
src/lib/VSDXMLHelper.cpp | 20 +++
src/lib/VSDXMLHelper.h | 5
src/lib/VSDXMLParserBase.cpp | 216 +++++++++++++++----------------------------
src/lib/VSDXParser.cpp | 165 +++++++++++++-------------------
src/lib/VSDXTheme.cpp | 11 +-
src/lib/libvisio_utils.h | 4
7 files changed, 182 insertions(+), 240 deletions(-)
New commits:
commit 5e0cf3b1972fa26d28209a828933d2a6f95b49b1
Author: David Tardon <dtardon at redhat.com>
Date: Tue Jul 14 17:43:42 2015 +0200
avoid memory leak
Change-Id: Ibd1e042f11f0191bda0a4ae3064df603137fe5ba
diff --git a/src/lib/VSDXMLParserBase.cpp b/src/lib/VSDXMLParserBase.cpp
index 23c9778..12fe447 100644
--- a/src/lib/VSDXMLParserBase.cpp
+++ b/src/lib/VSDXMLParserBase.cpp
@@ -1197,8 +1197,8 @@ void libvisio::VSDXMLParserBase::readCharIX(xmlTextReaderPtr reader)
case XML_FONT:
if (XML_READER_TYPE_ELEMENT == tokenType)
{
- xmlChar *stringValue = readStringData(reader);
- if (stringValue && !xmlStrEqual(stringValue, BAD_CAST("Themed")))
+ const shared_ptr<xmlChar> stringValue(readStringData(reader), xmlFree);
+ if (stringValue && !xmlStrEqual(stringValue.get(), BAD_CAST("Themed")))
{
try
{
@@ -1207,11 +1207,11 @@ void libvisio::VSDXMLParserBase::readCharIX(xmlTextReaderPtr reader)
if (iter != m_fonts.end())
font = iter->second;
else
- font = VSDName(librevenge::RVNGBinaryData(stringValue, xmlStrlen(stringValue)), VSD_TEXT_UTF8);
+ font = VSDName(librevenge::RVNGBinaryData(stringValue.get(), xmlStrlen(stringValue.get())), VSD_TEXT_UTF8);
}
catch (const XmlParserException &)
{
- font = VSDName(librevenge::RVNGBinaryData(stringValue, xmlStrlen(stringValue)), VSD_TEXT_UTF8);
+ font = VSDName(librevenge::RVNGBinaryData(stringValue.get(), xmlStrlen(stringValue.get())), VSD_TEXT_UTF8);
}
}
}
commit 13eba01e48420e17525f271a0b1f9124fd22a8a2
Author: David Tardon <dtardon at redhat.com>
Date: Tue Jul 14 17:41:52 2015 +0200
fix more string leaks
Change-Id: Ifc79cf5d91a262fb4d51d13d9d183164ccc24f07
diff --git a/src/lib/VSDXTheme.cpp b/src/lib/VSDXTheme.cpp
index 85cf0ac..f962105 100644
--- a/src/lib/VSDXTheme.cpp
+++ b/src/lib/VSDXTheme.cpp
@@ -8,9 +8,14 @@
*/
#include "VSDXTheme.h"
+
+#include <boost/shared_ptr.hpp>
+
#include "VSDXMLTokenMap.h"
#include "libvisio_utils.h"
+using boost::shared_ptr;
+
libvisio::VSDXVariationClrScheme::VSDXVariationClrScheme()
: m_varColor1()
, m_varColor2()
@@ -96,7 +101,7 @@ boost::optional<libvisio::Colour> libvisio::VSDXTheme::readSrgbClr(xmlTextReader
boost::optional<libvisio::Colour> retVal;
if (XML_A_SRGBCLR == getElementToken(reader))
{
- xmlChar *val = xmlTextReaderGetAttribute(reader, BAD_CAST("val"));
+ const shared_ptr<xmlChar> val(xmlTextReaderGetAttribute(reader, BAD_CAST("val")), xmlFree);
if (val)
{
try
@@ -106,7 +111,6 @@ boost::optional<libvisio::Colour> libvisio::VSDXTheme::readSrgbClr(xmlTextReader
catch (const XmlParserException &)
{
}
- xmlFree(val);
}
}
return retVal;
@@ -117,7 +121,7 @@ boost::optional<libvisio::Colour> libvisio::VSDXTheme::readSysClr(xmlTextReaderP
boost::optional<libvisio::Colour> retVal;
if (XML_A_SYSCLR == getElementToken(reader))
{
- xmlChar *lastClr = xmlTextReaderGetAttribute(reader, BAD_CAST("lastClr"));
+ const shared_ptr<xmlChar> lastClr(xmlTextReaderGetAttribute(reader, BAD_CAST("lastClr")), xmlFree);
if (lastClr)
{
try
@@ -127,7 +131,6 @@ boost::optional<libvisio::Colour> libvisio::VSDXTheme::readSysClr(xmlTextReaderP
catch (const XmlParserException &)
{
}
- xmlFree(lastClr);
}
}
return retVal;
commit 5409f4e852318f59fc59bf56701205095954073b
Author: David Tardon <dtardon at redhat.com>
Date: Tue Jul 14 17:39:28 2015 +0200
avoid a slew of string leaks
Change-Id: I72b02e1752df97501a0c1a5aef123f7f43dcdd2f
diff --git a/src/lib/VSDXMLHelper.cpp b/src/lib/VSDXMLHelper.cpp
index 4180316..582763e 100644
--- a/src/lib/VSDXMLHelper.cpp
+++ b/src/lib/VSDXMLHelper.cpp
@@ -120,6 +120,11 @@ libvisio::Colour libvisio::xmlStringToColour(const xmlChar *s)
return Colour((val & 0xff0000) >> 16, (val & 0xff00) >> 8, val & 0xff, 0);
}
+libvisio::Colour libvisio::xmlStringToColour(const boost::shared_ptr<xmlChar> &s)
+{
+ return xmlStringToColour(s.get());
+}
+
long libvisio::xmlStringToLong(const xmlChar *s)
{
using boost::lexical_cast;
@@ -139,6 +144,11 @@ long libvisio::xmlStringToLong(const xmlChar *s)
return 0;
}
+long libvisio::xmlStringToLong(const boost::shared_ptr<xmlChar> &s)
+{
+ return xmlStringToLong(s.get());
+}
+
double libvisio::xmlStringToDouble(const xmlChar *s) try
{
if (xmlStrEqual(s, BAD_CAST("Themed")))
@@ -152,6 +162,11 @@ catch (const boost::bad_lexical_cast &)
throw XmlParserException();
}
+double libvisio::xmlStringToDouble(const boost::shared_ptr<xmlChar> &s)
+{
+ return xmlStringToDouble(s.get());
+}
+
bool libvisio::xmlStringToBool(const xmlChar *s)
{
if (xmlStrEqual(s, BAD_CAST("Themed")))
@@ -171,6 +186,11 @@ bool libvisio::xmlStringToBool(const xmlChar *s)
}
+bool libvisio::xmlStringToBool(const boost::shared_ptr<xmlChar> &s)
+{
+ return xmlStringToBool(s.get());
+}
+
// VSDXRelationship
libvisio::VSDXRelationship::VSDXRelationship(xmlTextReaderPtr reader)
diff --git a/src/lib/VSDXMLHelper.h b/src/lib/VSDXMLHelper.h
index bf14baa..588ca50 100644
--- a/src/lib/VSDXMLHelper.h
+++ b/src/lib/VSDXMLHelper.h
@@ -12,6 +12,7 @@
#include <map>
#include <string>
+#include <boost/shared_ptr.hpp>
#include <librevenge-stream/librevenge-stream.h>
#include <libxml/xmlreader.h>
#include "VSDTypes.h"
@@ -28,12 +29,16 @@ xmlTextReaderPtr xmlReaderForStream(librevenge::RVNGInputStream *input,
int options);
Colour xmlStringToColour(const xmlChar *s);
+Colour xmlStringToColour(const boost::shared_ptr<xmlChar> &s);
long xmlStringToLong(const xmlChar *s);
+long xmlStringToLong(const boost::shared_ptr<xmlChar> &s);
double xmlStringToDouble(const xmlChar *s);
+double xmlStringToDouble(const boost::shared_ptr<xmlChar> &s);
bool xmlStringToBool(const xmlChar *s);
+bool xmlStringToBool(const boost::shared_ptr<xmlChar> &s);
class VSDCollector;
diff --git a/src/lib/VSDXMLParserBase.cpp b/src/lib/VSDXMLParserBase.cpp
index 8b6d204..23c9778 100644
--- a/src/lib/VSDXMLParserBase.cpp
+++ b/src/lib/VSDXMLParserBase.cpp
@@ -21,6 +21,7 @@
#include "VSDXMLHelper.h"
#include "VSDXMLTokenMap.h"
+using boost::shared_ptr;
libvisio::VSDXMLParserBase::VSDXMLParserBase()
: m_collector(), m_stencils(), m_currentStencil(0), m_shape(),
@@ -55,7 +56,7 @@ void libvisio::VSDXMLParserBase::readGeometry(xmlTextReaderPtr reader)
if (xmlTextReaderIsEmptyElement(reader))
{
- xmlChar *delString = xmlTextReaderGetAttribute(reader, BAD_CAST("Del"));
+ const shared_ptr<xmlChar> delString(xmlTextReaderGetAttribute(reader, BAD_CAST("Del")), xmlFree);
if (delString)
{
if (xmlStringToBool(delString))
@@ -63,7 +64,6 @@ void libvisio::VSDXMLParserBase::readGeometry(xmlTextReaderPtr reader)
m_currentGeometryList->clear();
m_shape.m_geometries.erase(ix);
}
- xmlFree(delString);
}
return;
}
@@ -176,12 +176,11 @@ void libvisio::VSDXMLParserBase::readMoveTo(xmlTextReaderPtr reader)
if (xmlTextReaderIsEmptyElement(reader))
{
- xmlChar *delString = xmlTextReaderGetAttribute(reader, BAD_CAST("Del"));
+ const shared_ptr<xmlChar> delString(xmlTextReaderGetAttribute(reader, BAD_CAST("Del")), xmlFree);
if (delString)
{
if (xmlStringToBool(delString))
m_currentGeometryList->addEmpty(ix, level);
- xmlFree(delString);
}
return;
}
@@ -227,12 +226,11 @@ void libvisio::VSDXMLParserBase::readLineTo(xmlTextReaderPtr reader)
if (xmlTextReaderIsEmptyElement(reader))
{
- xmlChar *delString = xmlTextReaderGetAttribute(reader, BAD_CAST("Del"));
+ const shared_ptr<xmlChar> delString(xmlTextReaderGetAttribute(reader, BAD_CAST("Del")), xmlFree);
if (delString)
{
if (xmlStringToBool(delString))
m_currentGeometryList->addEmpty(ix, level);
- xmlFree(delString);
}
return;
}
@@ -278,12 +276,11 @@ void libvisio::VSDXMLParserBase::readArcTo(xmlTextReaderPtr reader)
if (xmlTextReaderIsEmptyElement(reader))
{
- xmlChar *delString = xmlTextReaderGetAttribute(reader, BAD_CAST("Del"));
+ const shared_ptr<xmlChar> delString(xmlTextReaderGetAttribute(reader, BAD_CAST("Del")), xmlFree);
if (delString)
{
if (xmlStringToBool(delString))
m_currentGeometryList->addEmpty(ix, level);
- xmlFree(delString);
}
return;
}
@@ -333,12 +330,11 @@ void libvisio::VSDXMLParserBase::readEllipticalArcTo(xmlTextReaderPtr reader)
if (xmlTextReaderIsEmptyElement(reader))
{
- xmlChar *delString = xmlTextReaderGetAttribute(reader, BAD_CAST("Del"));
+ const shared_ptr<xmlChar> delString(xmlTextReaderGetAttribute(reader, BAD_CAST("Del")), xmlFree);
if (delString)
{
if (xmlStringToBool(delString))
m_currentGeometryList->addEmpty(ix, level);
- xmlFree(delString);
}
return;
}
@@ -400,12 +396,11 @@ void libvisio::VSDXMLParserBase::readEllipse(xmlTextReaderPtr reader)
if (xmlTextReaderIsEmptyElement(reader))
{
- xmlChar *delString = xmlTextReaderGetAttribute(reader, BAD_CAST("Del"));
+ const shared_ptr<xmlChar> delString(xmlTextReaderGetAttribute(reader, BAD_CAST("Del")), xmlFree);
if (delString)
{
if (xmlStringToBool(delString))
m_currentGeometryList->addEmpty(ix, level);
- xmlFree(delString);
}
return;
}
@@ -467,12 +462,11 @@ void libvisio::VSDXMLParserBase::readNURBSTo(xmlTextReaderPtr reader)
if (xmlTextReaderIsEmptyElement(reader))
{
- xmlChar *delString = xmlTextReaderGetAttribute(reader, BAD_CAST("Del"));
+ const shared_ptr<xmlChar> delString(xmlTextReaderGetAttribute(reader, BAD_CAST("Del")), xmlFree);
if (delString)
{
if (xmlStringToBool(delString))
m_currentGeometryList->addEmpty(ix, level);
- xmlFree(delString);
}
return;
}
@@ -539,12 +533,11 @@ void libvisio::VSDXMLParserBase::readPolylineTo(xmlTextReaderPtr reader)
if (xmlTextReaderIsEmptyElement(reader))
{
- xmlChar *delString = xmlTextReaderGetAttribute(reader, BAD_CAST("Del"));
+ const shared_ptr<xmlChar> delString(xmlTextReaderGetAttribute(reader, BAD_CAST("Del")), xmlFree);
if (delString)
{
if (xmlStringToBool(delString))
m_currentGeometryList->addEmpty(ix, level);
- xmlFree(delString);
}
return;
}
@@ -594,12 +587,11 @@ void libvisio::VSDXMLParserBase::readInfiniteLine(xmlTextReaderPtr reader)
if (xmlTextReaderIsEmptyElement(reader))
{
- xmlChar *delString = xmlTextReaderGetAttribute(reader, BAD_CAST("Del"));
+ const shared_ptr<xmlChar> delString(xmlTextReaderGetAttribute(reader, BAD_CAST("Del")), xmlFree);
if (delString)
{
if (xmlStringToBool(delString))
m_currentGeometryList->addEmpty(ix, level);
- xmlFree(delString);
}
return;
}
@@ -653,12 +645,11 @@ void libvisio::VSDXMLParserBase::readRelEllipticalArcTo(xmlTextReaderPtr reader)
if (xmlTextReaderIsEmptyElement(reader))
{
- xmlChar *delString = xmlTextReaderGetAttribute(reader, BAD_CAST("Del"));
+ const shared_ptr<xmlChar> delString(xmlTextReaderGetAttribute(reader, BAD_CAST("Del")), xmlFree);
if (delString)
{
if (xmlStringToBool(delString))
m_currentGeometryList->addEmpty(ix, level);
- xmlFree(delString);
}
return;
}
@@ -720,12 +711,11 @@ void libvisio::VSDXMLParserBase::readRelCubBezTo(xmlTextReaderPtr reader)
if (xmlTextReaderIsEmptyElement(reader))
{
- xmlChar *delString = xmlTextReaderGetAttribute(reader, BAD_CAST("Del"));
+ const shared_ptr<xmlChar> delString(xmlTextReaderGetAttribute(reader, BAD_CAST("Del")), xmlFree);
if (delString)
{
if (xmlStringToBool(delString))
m_currentGeometryList->addEmpty(ix, level);
- xmlFree(delString);
}
return;
}
@@ -787,12 +777,11 @@ void libvisio::VSDXMLParserBase::readRelLineTo(xmlTextReaderPtr reader)
if (xmlTextReaderIsEmptyElement(reader))
{
- xmlChar *delString = xmlTextReaderGetAttribute(reader, BAD_CAST("Del"));
+ const shared_ptr<xmlChar> delString(xmlTextReaderGetAttribute(reader, BAD_CAST("Del")), xmlFree);
if (delString)
{
if (xmlStringToBool(delString))
m_currentGeometryList->addEmpty(ix, level);
- xmlFree(delString);
}
return;
}
@@ -838,12 +827,11 @@ void libvisio::VSDXMLParserBase::readRelMoveTo(xmlTextReaderPtr reader)
if (xmlTextReaderIsEmptyElement(reader))
{
- xmlChar *delString = xmlTextReaderGetAttribute(reader, BAD_CAST("Del"));
+ const shared_ptr<xmlChar> delString(xmlTextReaderGetAttribute(reader, BAD_CAST("Del")), xmlFree);
if (delString)
{
if (xmlStringToBool(delString))
m_currentGeometryList->addEmpty(ix, level);
- xmlFree(delString);
}
return;
}
@@ -889,12 +877,11 @@ void libvisio::VSDXMLParserBase::readRelQuadBezTo(xmlTextReaderPtr reader)
if (xmlTextReaderIsEmptyElement(reader))
{
- xmlChar *delString = xmlTextReaderGetAttribute(reader, BAD_CAST("Del"));
+ const shared_ptr<xmlChar> delString(xmlTextReaderGetAttribute(reader, BAD_CAST("Del")), xmlFree);
if (delString)
{
if (xmlStringToBool(delString))
m_currentGeometryList->addEmpty(ix, level);
- xmlFree(delString);
}
return;
}
@@ -942,12 +929,12 @@ void libvisio::VSDXMLParserBase::readShape(xmlTextReaderPtr reader)
m_isShapeStarted = true;
m_currentShapeLevel = getElementDepth(reader);
- xmlChar *idString = xmlTextReaderGetAttribute(reader, BAD_CAST("ID"));
- xmlChar *masterPageString = xmlTextReaderGetAttribute(reader, BAD_CAST("Master"));
- xmlChar *masterShapeString = xmlTextReaderGetAttribute(reader, BAD_CAST("MasterShape"));
- xmlChar *lineStyleString = xmlTextReaderGetAttribute(reader, BAD_CAST("LineStyle"));
- xmlChar *fillStyleString = xmlTextReaderGetAttribute(reader, BAD_CAST("FillStyle"));
- xmlChar *textStyleString = xmlTextReaderGetAttribute(reader, BAD_CAST("TextStyle"));
+ const shared_ptr<xmlChar> idString(xmlTextReaderGetAttribute(reader, BAD_CAST("ID")), xmlFree);
+ const shared_ptr<xmlChar> masterPageString(xmlTextReaderGetAttribute(reader, BAD_CAST("Master")), xmlFree);
+ const shared_ptr<xmlChar> masterShapeString(xmlTextReaderGetAttribute(reader, BAD_CAST("MasterShape")), xmlFree);
+ const shared_ptr<xmlChar> lineStyleString(xmlTextReaderGetAttribute(reader, BAD_CAST("LineStyle")), xmlFree);
+ const shared_ptr<xmlChar> fillStyleString(xmlTextReaderGetAttribute(reader, BAD_CAST("FillStyle")), xmlFree);
+ const shared_ptr<xmlChar> textStyleString(xmlTextReaderGetAttribute(reader, BAD_CAST("TextStyle")), xmlFree);
unsigned id = idString ? (unsigned)xmlStringToLong(idString) : MINUS_ONE;
unsigned masterPage = masterPageString ? (unsigned)xmlStringToLong(masterPageString) : MINUS_ONE;
@@ -956,19 +943,6 @@ void libvisio::VSDXMLParserBase::readShape(xmlTextReaderPtr reader)
unsigned fillStyle = fillStyleString ? (unsigned)xmlStringToLong(fillStyleString) : MINUS_ONE;
unsigned textStyle = textStyleString ? (unsigned)xmlStringToLong(textStyleString) : MINUS_ONE;
- if (idString)
- xmlFree(idString);
- if (masterPageString)
- xmlFree(masterPageString);
- if (masterShapeString)
- xmlFree(masterShapeString);
- if (lineStyleString)
- xmlFree(lineStyleString);
- if (fillStyleString)
- xmlFree(fillStyleString);
- if (textStyleString)
- xmlFree(textStyleString);
-
if (masterPage != MINUS_ONE || masterShape != MINUS_ONE)
{
if (!m_shapeStack.empty())
@@ -1067,14 +1041,12 @@ void libvisio::VSDXMLParserBase::readColours(xmlTextReaderPtr reader)
if (XML_COLORENTRY == tokenId)
{
unsigned idx = getIX(reader);
- xmlChar *rgb = xmlTextReaderGetAttribute(reader, BAD_CAST("RGB"));
+ const shared_ptr<xmlChar> rgb(xmlTextReaderGetAttribute(reader, BAD_CAST("RGB")), xmlFree);
if (MINUS_ONE != idx && rgb)
{
Colour rgbColour = xmlStringToColour(rgb);
m_colours[idx] = rgbColour;
}
- if (rgb)
- xmlFree(rgb);
}
}
while ((XML_COLORS != tokenId || XML_READER_TYPE_END_ELEMENT != tokenType) && 1 == ret);
@@ -1083,10 +1055,10 @@ void libvisio::VSDXMLParserBase::readColours(xmlTextReaderPtr reader)
void libvisio::VSDXMLParserBase::readPage(xmlTextReaderPtr reader)
{
m_shapeList.clear();
- xmlChar *id = xmlTextReaderGetAttribute(reader, BAD_CAST("ID"));
- xmlChar *bgndPage = xmlTextReaderGetAttribute(reader, BAD_CAST("BackPage"));
- xmlChar *background = xmlTextReaderGetAttribute(reader, BAD_CAST("Background"));
- xmlChar *pageName = xmlTextReaderGetAttribute(reader, BAD_CAST("NameU"));
+ const shared_ptr<xmlChar> id(xmlTextReaderGetAttribute(reader, BAD_CAST("ID")), xmlFree);
+ const shared_ptr<xmlChar> bgndPage(xmlTextReaderGetAttribute(reader, BAD_CAST("BackPage")), xmlFree);
+ const shared_ptr<xmlChar> background(xmlTextReaderGetAttribute(reader, BAD_CAST("Background")), xmlFree);
+ const shared_ptr<xmlChar> pageName(xmlTextReaderGetAttribute(reader, BAD_CAST("NameU")), xmlFree);
if (id)
{
unsigned nId = (unsigned)xmlStringToLong(id);
@@ -1094,16 +1066,8 @@ void libvisio::VSDXMLParserBase::readPage(xmlTextReaderPtr reader)
bool isBackgroundPage = background ? xmlStringToBool(background) : false;
m_isPageStarted = true;
m_collector->startPage(nId);
- m_collector->collectPage(nId, (unsigned)getElementDepth(reader), backgroundPageID, isBackgroundPage, pageName ? VSDName(librevenge::RVNGBinaryData(pageName, xmlStrlen(pageName)), VSD_TEXT_UTF8) : VSDName());
+ m_collector->collectPage(nId, (unsigned)getElementDepth(reader), backgroundPageID, isBackgroundPage, pageName ? VSDName(librevenge::RVNGBinaryData(pageName.get(), xmlStrlen(pageName.get())), VSD_TEXT_UTF8) : VSDName());
}
- if (id)
- xmlFree(id);
- if (bgndPage)
- xmlFree(bgndPage);
- if (background)
- xmlFree(background);
- if (pageName)
- xmlFree(pageName);
}
void libvisio::VSDXMLParserBase::readText(xmlTextReaderPtr reader)
@@ -1250,8 +1214,6 @@ void libvisio::VSDXMLParserBase::readCharIX(xmlTextReaderPtr reader)
font = VSDName(librevenge::RVNGBinaryData(stringValue, xmlStrlen(stringValue)), VSD_TEXT_UTF8);
}
}
- if (stringValue)
- xmlFree(stringValue);
}
break;
case XML_COLOR:
@@ -1459,10 +1421,10 @@ void libvisio::VSDXMLParserBase::readParaIX(xmlTextReaderPtr reader)
void libvisio::VSDXMLParserBase::readStyleSheet(xmlTextReaderPtr reader)
{
- xmlChar *id = xmlTextReaderGetAttribute(reader, BAD_CAST("ID"));
- xmlChar *lineStyle = xmlTextReaderGetAttribute(reader, BAD_CAST("LineStyle"));
- xmlChar *fillStyle = xmlTextReaderGetAttribute(reader, BAD_CAST("FillStyle"));
- xmlChar *textStyle = xmlTextReaderGetAttribute(reader, BAD_CAST("TextStyle"));
+ const shared_ptr<xmlChar> id(xmlTextReaderGetAttribute(reader, BAD_CAST("ID")), xmlFree);
+ const shared_ptr<xmlChar> lineStyle(xmlTextReaderGetAttribute(reader, BAD_CAST("LineStyle")), xmlFree);
+ const shared_ptr<xmlChar> fillStyle(xmlTextReaderGetAttribute(reader, BAD_CAST("FillStyle")), xmlFree);
+ const shared_ptr<xmlChar> textStyle(xmlTextReaderGetAttribute(reader, BAD_CAST("TextStyle")), xmlFree);
if (id)
{
unsigned nId = (unsigned)xmlStringToLong(id);
@@ -1471,14 +1433,6 @@ void libvisio::VSDXMLParserBase::readStyleSheet(xmlTextReaderPtr reader)
unsigned nTextStyle = (unsigned)(textStyle ? xmlStringToLong(textStyle) : -1);
m_collector->collectStyleSheet(nId, (unsigned)getElementDepth(reader), nLineStyle, nFillStyle, nTextStyle);
}
- if (id)
- xmlFree(id);
- if (lineStyle)
- xmlFree(lineStyle);
- if (fillStyle)
- xmlFree(fillStyle);
- if (textStyle)
- xmlFree(textStyle);
}
void libvisio::VSDXMLParserBase::readPageSheet(xmlTextReaderPtr reader)
@@ -1498,12 +1452,11 @@ void libvisio::VSDXMLParserBase::readSplineStart(xmlTextReaderPtr reader)
if (xmlTextReaderIsEmptyElement(reader))
{
- xmlChar *delString = xmlTextReaderGetAttribute(reader, BAD_CAST("Del"));
+ const shared_ptr<xmlChar> delString(xmlTextReaderGetAttribute(reader, BAD_CAST("Del")), xmlFree);
if (delString)
{
if (xmlStringToBool(delString))
m_currentGeometryList->addEmpty(ix, level);
- xmlFree(delString);
}
return;
}
@@ -1565,12 +1518,11 @@ void libvisio::VSDXMLParserBase::readSplineKnot(xmlTextReaderPtr reader)
if (xmlTextReaderIsEmptyElement(reader))
{
- xmlChar *delString = xmlTextReaderGetAttribute(reader, BAD_CAST("Del"));
+ const shared_ptr<xmlChar> delString(xmlTextReaderGetAttribute(reader, BAD_CAST("Del")), xmlFree);
if (delString)
{
if (xmlStringToBool(delString))
m_currentGeometryList->addEmpty(ix, level);
- xmlFree(delString);
}
return;
}
@@ -1611,12 +1563,11 @@ void libvisio::VSDXMLParserBase::readSplineKnot(xmlTextReaderPtr reader)
void libvisio::VSDXMLParserBase::readStencil(xmlTextReaderPtr reader)
{
- xmlChar *id = xmlTextReaderGetAttribute(reader, BAD_CAST("ID"));
+ const shared_ptr<xmlChar> id(xmlTextReaderGetAttribute(reader, BAD_CAST("ID")), xmlFree);
if (id)
{
unsigned nId = (unsigned)xmlStringToLong(id);
m_currentStencilID = nId;
- xmlFree(id);
}
else
m_currentStencilID = MINUS_ONE;
@@ -1631,33 +1582,31 @@ void libvisio::VSDXMLParserBase::readForeignData(xmlTextReaderPtr reader)
if (!m_shape.m_foreign)
m_shape.m_foreign = new ForeignData();
- xmlChar *foreignTypeString = xmlTextReaderGetAttribute(reader, BAD_CAST("ForeignType"));
+ const shared_ptr<xmlChar> foreignTypeString(xmlTextReaderGetAttribute(reader, BAD_CAST("ForeignType")), xmlFree);
if (foreignTypeString)
{
- if (xmlStrEqual(foreignTypeString, BAD_CAST("Bitmap")))
+ if (xmlStrEqual(foreignTypeString.get(), BAD_CAST("Bitmap")))
m_shape.m_foreign->type = 1;
- else if (xmlStrEqual(foreignTypeString, BAD_CAST("Object")))
+ else if (xmlStrEqual(foreignTypeString.get(), BAD_CAST("Object")))
m_shape.m_foreign->type = 2;
- else if (xmlStrEqual(foreignTypeString, BAD_CAST("EnhMetaFile")))
+ else if (xmlStrEqual(foreignTypeString.get(), BAD_CAST("EnhMetaFile")))
m_shape.m_foreign->type = 4;
- else if (xmlStrEqual(foreignTypeString, BAD_CAST("MetaFile")))
+ else if (xmlStrEqual(foreignTypeString.get(), BAD_CAST("MetaFile")))
m_shape.m_foreign->type = 0;
- xmlFree(foreignTypeString);
}
- xmlChar *foreignFormatString = xmlTextReaderGetAttribute(reader, BAD_CAST("CompressionType"));
+ const shared_ptr<xmlChar> foreignFormatString(xmlTextReaderGetAttribute(reader, BAD_CAST("CompressionType")), xmlFree);
if (foreignFormatString)
{
- if (xmlStrEqual(foreignFormatString, BAD_CAST("JPEG")))
+ if (xmlStrEqual(foreignFormatString.get(), BAD_CAST("JPEG")))
m_shape.m_foreign->format = 1;
- else if (xmlStrEqual(foreignFormatString, BAD_CAST("GIF")))
+ else if (xmlStrEqual(foreignFormatString.get(), BAD_CAST("GIF")))
m_shape.m_foreign->format = 2;
- else if (xmlStrEqual(foreignFormatString, BAD_CAST("TIFF")))
+ else if (xmlStrEqual(foreignFormatString.get(), BAD_CAST("TIFF")))
m_shape.m_foreign->format = 3;
- else if (xmlStrEqual(foreignFormatString, BAD_CAST("PNG")))
+ else if (xmlStrEqual(foreignFormatString.get(), BAD_CAST("PNG")))
m_shape.m_foreign->format = 4;
else
m_shape.m_foreign->format = 0;
- xmlFree(foreignFormatString);
}
else
m_shape.m_foreign->format = 255;
@@ -1886,13 +1835,13 @@ int libvisio::VSDXMLParserBase::readNURBSData(boost::optional<NURBSData> &data,
NURBSData tmpData;
bool bRes = false;
- xmlChar *formula = readStringData(reader);
+ const shared_ptr<xmlChar> formula(readStringData(reader), xmlFree);
if (formula)
{
std::pair<double, double> point;
- bRes = parse((const char *)formula,
+ bRes = parse((const char *)formula.get(),
// Begin grammar
(
str_p("NURBS")
@@ -1912,8 +1861,6 @@ int libvisio::VSDXMLParserBase::readNURBSData(boost::optional<NURBSData> &data,
) >> ')' >> end_p,
// End grammar
space_p).full;
-
- xmlFree(formula);
}
if (!bRes)
@@ -1929,13 +1876,13 @@ int libvisio::VSDXMLParserBase::readPolylineData(boost::optional<PolylineData> &
PolylineData tmpData;
bool bRes = false;
- xmlChar *formula = readStringData(reader);
+ const shared_ptr<xmlChar> formula(readStringData(reader), xmlFree);
if (formula)
{
std::pair<double, double> point;
- bRes = parse((const char *)formula,
+ bRes = parse((const char *)formula.get(),
// Begin grammar
(
str_p("POLYLINE")
@@ -1950,8 +1897,6 @@ int libvisio::VSDXMLParserBase::readPolylineData(boost::optional<PolylineData> &
) >> ')' >> end_p,
// End grammar
space_p).full;
-
- xmlFree(formula);
}
if (!bRes)
@@ -1963,13 +1908,12 @@ int libvisio::VSDXMLParserBase::readPolylineData(boost::optional<PolylineData> &
int libvisio::VSDXMLParserBase::readDoubleData(double &value, xmlTextReaderPtr reader)
{
- xmlChar *stringValue = readStringData(reader);
+ const shared_ptr<xmlChar> stringValue(readStringData(reader), xmlFree);
if (stringValue)
{
- VSD_DEBUG_MSG(("VSDXMLParserBase::readDoubleData stringValue %s\n", (const char *)stringValue));
- if (!xmlStrEqual(stringValue, BAD_CAST("Themed")))
+ VSD_DEBUG_MSG(("VSDXMLParserBase::readDoubleData stringValue %s\n", (const char *)stringValue.get()));
+ if (!xmlStrEqual(stringValue.get(), BAD_CAST("Themed")))
value = xmlStringToDouble(stringValue);
- xmlFree(stringValue);
return 1;
}
return -1;
@@ -1977,13 +1921,12 @@ int libvisio::VSDXMLParserBase::readDoubleData(double &value, xmlTextReaderPtr r
int libvisio::VSDXMLParserBase::readDoubleData(boost::optional<double> &value, xmlTextReaderPtr reader)
{
- xmlChar *stringValue = readStringData(reader);
+ const shared_ptr<xmlChar> stringValue(readStringData(reader), xmlFree);
if (stringValue)
{
- VSD_DEBUG_MSG(("VSDXMLParserBase::readDoubleData stringValue %s\n", (const char *)stringValue));
- if (!xmlStrEqual(stringValue, BAD_CAST("Themed")))
+ VSD_DEBUG_MSG(("VSDXMLParserBase::readDoubleData stringValue %s\n", (const char *)stringValue.get()));
+ if (!xmlStrEqual(stringValue.get(), BAD_CAST("Themed")))
value = xmlStringToDouble(stringValue);
- xmlFree(stringValue);
return 1;
}
return -1;
@@ -1991,13 +1934,12 @@ int libvisio::VSDXMLParserBase::readDoubleData(boost::optional<double> &value, x
int libvisio::VSDXMLParserBase::readLongData(long &value, xmlTextReaderPtr reader)
{
- xmlChar *stringValue = readStringData(reader);
+ const shared_ptr<xmlChar> stringValue(readStringData(reader), xmlFree);
if (stringValue)
{
- VSD_DEBUG_MSG(("VSDXMLParserBase::readLongData stringValue %s\n", (const char *)stringValue));
- if (!xmlStrEqual(stringValue, BAD_CAST("Themed")))
+ VSD_DEBUG_MSG(("VSDXMLParserBase::readLongData stringValue %s\n", (const char *)stringValue.get()));
+ if (!xmlStrEqual(stringValue.get(), BAD_CAST("Themed")))
value = xmlStringToLong(stringValue);
- xmlFree(stringValue);
return 1;
}
return -1;
@@ -2005,13 +1947,12 @@ int libvisio::VSDXMLParserBase::readLongData(long &value, xmlTextReaderPtr reade
int libvisio::VSDXMLParserBase::readLongData(boost::optional<long> &value, xmlTextReaderPtr reader)
{
- xmlChar *stringValue = readStringData(reader);
+ const shared_ptr<xmlChar> stringValue(readStringData(reader), xmlFree);
if (stringValue)
{
- VSD_DEBUG_MSG(("VSDXMLParserBase::readLongData stringValue %s\n", (const char *)stringValue));
- if (!xmlStrEqual(stringValue, BAD_CAST("Themed")))
+ VSD_DEBUG_MSG(("VSDXMLParserBase::readLongData stringValue %s\n", (const char *)stringValue.get()));
+ if (!xmlStrEqual(stringValue.get(), BAD_CAST("Themed")))
value = xmlStringToLong(stringValue);
- xmlFree(stringValue);
return 1;
}
return -1;
@@ -2019,13 +1960,12 @@ int libvisio::VSDXMLParserBase::readLongData(boost::optional<long> &value, xmlTe
int libvisio::VSDXMLParserBase::readBoolData(bool &value, xmlTextReaderPtr reader)
{
- xmlChar *stringValue = readStringData(reader);
+ const shared_ptr<xmlChar> stringValue(readStringData(reader), xmlFree);
if (stringValue)
{
- VSD_DEBUG_MSG(("VSDXMLParserBase::readBoolData stringValue %s\n", (const char *)stringValue));
- if (!xmlStrEqual(stringValue, BAD_CAST("Themed")))
+ VSD_DEBUG_MSG(("VSDXMLParserBase::readBoolData stringValue %s\n", (const char *)stringValue.get()));
+ if (!xmlStrEqual(stringValue.get(), BAD_CAST("Themed")))
value = xmlStringToBool(stringValue);
- xmlFree(stringValue);
return 1;
}
return -1;
@@ -2033,13 +1973,12 @@ int libvisio::VSDXMLParserBase::readBoolData(bool &value, xmlTextReaderPtr reade
int libvisio::VSDXMLParserBase::readBoolData(boost::optional<bool> &value, xmlTextReaderPtr reader)
{
- xmlChar *stringValue = readStringData(reader);
+ const shared_ptr<xmlChar> stringValue(readStringData(reader), xmlFree);
if (stringValue)
{
- VSD_DEBUG_MSG(("VSDXMLParserBase::readBoolData stringValue %s\n", (const char *)stringValue));
- if (!xmlStrEqual(stringValue, BAD_CAST("Themed")))
+ VSD_DEBUG_MSG(("VSDXMLParserBase::readBoolData stringValue %s\n", (const char *)stringValue.get()));
+ if (!xmlStrEqual(stringValue.get(), BAD_CAST("Themed")))
value = xmlStringToBool(stringValue);
- xmlFree(stringValue);
return 1;
}
return -1;
@@ -2073,11 +2012,11 @@ int libvisio::VSDXMLParserBase::readByteData(boost::optional<unsigned char> &val
int libvisio::VSDXMLParserBase::readExtendedColourData(Colour &value, long &idx, xmlTextReaderPtr reader)
{
- xmlChar *stringValue = readStringData(reader);
+ const shared_ptr<xmlChar> stringValue(readStringData(reader), xmlFree);
if (stringValue)
{
- VSD_DEBUG_MSG(("VSDXMLParserBase::readColourData stringValue %s\n", (const char *)stringValue));
- if (!xmlStrEqual(stringValue, BAD_CAST("Themed")))
+ VSD_DEBUG_MSG(("VSDXMLParserBase::readColourData stringValue %s\n", (const char *)stringValue.get()));
+ if (!xmlStrEqual(stringValue.get(), BAD_CAST("Themed")))
{
try
{
@@ -2096,7 +2035,6 @@ int libvisio::VSDXMLParserBase::readExtendedColourData(Colour &value, long &idx,
idx = -1;
}
}
- xmlFree(stringValue);
return 1;
}
return -1;
commit f6122c37edad438843660e4abf2792159a06a12d
Author: David Tardon <dtardon at redhat.com>
Date: Tue Jul 14 16:00:19 2015 +0200
avoid memory leak
Change-Id: I66851b20c42e5a740a0401a61e8536d9b3e0b503
diff --git a/src/lib/VSDXParser.cpp b/src/lib/VSDXParser.cpp
index d65308e..e889fff 100644
--- a/src/lib/VSDXParser.cpp
+++ b/src/lib/VSDXParser.cpp
@@ -12,6 +12,7 @@
#include <libxml/xmlstring.h>
#include <librevenge-stream/librevenge-stream.h>
#include <boost/algorithm/string.hpp>
+#include <boost/shared_ptr.hpp>
#include "VSDXParser.h"
#include "libvisio_utils.h"
#include "VSDContentCollector.h"
@@ -313,10 +314,10 @@ void libvisio::VSDXParser::processXmlDocument(librevenge::RVNGInputStream *input
case XML_REL:
if (XML_READER_TYPE_ELEMENT == tokenType)
{
- xmlChar *id = xmlTextReaderGetAttribute(reader.get(), BAD_CAST("r:id"));
+ boost::shared_ptr<xmlChar> id(xmlTextReaderGetAttribute(reader.get(), BAD_CAST("r:id")), xmlFree);
if (id)
{
- const VSDXRelationship *rel = rels.getRelationshipById((char *)id);
+ const VSDXRelationship *rel = rels.getRelationshipById((char *)id.get());
if (rel)
{
std::string type = rel->getType();
@@ -339,7 +340,6 @@ void libvisio::VSDXParser::processXmlDocument(librevenge::RVNGInputStream *input
else
processXmlNode(reader.get());
}
- xmlFree(id);
}
}
break;
commit 0aaab87fa47283c2dedc2c1c827fc56f0b24b74e
Author: David Tardon <dtardon at redhat.com>
Date: Tue Jul 14 15:56:17 2015 +0200
avoid memory leak in case of exception
Change-Id: I1129c4a3e779270c6c5e43229d3d31a6376eb3b3
diff --git a/src/lib/VSDXMLParserBase.cpp b/src/lib/VSDXMLParserBase.cpp
index fa74c71..8b6d204 100644
--- a/src/lib/VSDXMLParserBase.cpp
+++ b/src/lib/VSDXMLParserBase.cpp
@@ -12,6 +12,7 @@
#include <libxml/xmlstring.h>
#include <librevenge-stream/librevenge-stream.h>
#include <boost/algorithm/string.hpp>
+#include <boost/shared_ptr.hpp>
#include <boost/spirit/include/classic.hpp>
#include "VSDXMLParserBase.h"
#include "libvisio_utils.h"
@@ -2118,12 +2119,9 @@ int libvisio::VSDXMLParserBase::readExtendedColourData(Colour &value, xmlTextRea
unsigned libvisio::VSDXMLParserBase::getIX(xmlTextReaderPtr reader)
{
unsigned ix = MINUS_ONE;
- xmlChar *ixString = xmlTextReaderGetAttribute(reader, BAD_CAST("IX"));
+ const boost::shared_ptr<xmlChar> ixString(xmlTextReaderGetAttribute(reader, BAD_CAST("IX")), xmlFree);
if (ixString)
- {
- ix = (unsigned)xmlStringToLong(ixString);
- xmlFree(ixString);
- }
+ ix = (unsigned)xmlStringToLong(ixString.get());
return ix;
}
commit a69da92be817325e36e7ee5dcdb6c9d3146dad5a
Author: David Tardon <dtardon at redhat.com>
Date: Tue Jul 14 15:52:55 2015 +0200
avoid leak of xmlTextReader
Change-Id: If82d2b1a81a742a65d9826513e3d83b779602b7b
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)
commit e8e0700a9ac0c87e058678f64ae39d3eef4a11fd
Author: David Tardon <dtardon at redhat.com>
Date: Tue Jul 14 15:50:06 2015 +0200
use shared_ptr for streams
Change-Id: I3733f901ea75bfaf55941832890408de637a0417
diff --git a/src/lib/VSDXParser.cpp b/src/lib/VSDXParser.cpp
index 5063507..d2be71a 100644
--- a/src/lib/VSDXParser.cpp
+++ b/src/lib/VSDXParser.cpp
@@ -115,15 +115,13 @@ bool libvisio::VSDXParser::parseDocument(librevenge::RVNGInputStream *input, con
input->seek(0, librevenge::RVNG_SEEK_SET);
if (!input->isStructured())
return false;
- librevenge::RVNGInputStream *stream = input->getSubStreamByName(name);
+ const RVNGInputStreamPtr_t stream(input->getSubStreamByName(name));
input->seek(0, librevenge::RVNG_SEEK_SET);
if (!stream)
return false;
- librevenge::RVNGInputStream *relStream = input->getSubStreamByName(getRelationshipsForTarget(name).c_str());
+ const RVNGInputStreamPtr_t relStream(input->getSubStreamByName(getRelationshipsForTarget(name).c_str()));
input->seek(0, librevenge::RVNG_SEEK_SET);
- VSDXRelationships rels(relStream);
- if (relStream)
- delete relStream;
+ VSDXRelationships rels(relStream.get());
rels.rebaseTargets(getTargetBaseDirectory(name).c_str());
const VSDXRelationship *rel = rels.getRelationshipByType("http://schemas.openxmlformats.org/officeDocument/2006/relationships/theme");
@@ -136,7 +134,7 @@ bool libvisio::VSDXParser::parseDocument(librevenge::RVNGInputStream *input, con
input->seek(0, librevenge::RVNG_SEEK_SET);
}
- processXmlDocument(stream, rels);
+ processXmlDocument(stream.get(), rels);
rel = rels.getRelationshipByType("http://schemas.microsoft.com/visio/2010/relationships/masters");
if (rel)
@@ -158,8 +156,6 @@ bool libvisio::VSDXParser::parseDocument(librevenge::RVNGInputStream *input, con
input->seek(0, librevenge::RVNG_SEEK_SET);
}
- if (stream)
- delete stream;
return true;
}
@@ -170,19 +166,16 @@ bool libvisio::VSDXParser::parseMasters(librevenge::RVNGInputStream *input, cons
input->seek(0, librevenge::RVNG_SEEK_SET);
if (!input->isStructured())
return false;
- librevenge::RVNGInputStream *stream = input->getSubStreamByName(name);
+ const RVNGInputStreamPtr_t stream(input->getSubStreamByName(name));
if (!stream)
return false;
- librevenge::RVNGInputStream *relStream = input->getSubStreamByName(getRelationshipsForTarget(name).c_str());
+ const RVNGInputStreamPtr_t relStream(input->getSubStreamByName(getRelationshipsForTarget(name).c_str()));
input->seek(0, librevenge::RVNG_SEEK_SET);
- VSDXRelationships rels(relStream);
- if (relStream)
- delete relStream;
+ VSDXRelationships rels(relStream.get());
rels.rebaseTargets(getTargetBaseDirectory(name).c_str());
- processXmlDocument(stream, rels);
+ processXmlDocument(stream.get(), rels);
- delete stream;
return true;
}
@@ -193,19 +186,16 @@ bool libvisio::VSDXParser::parseMaster(librevenge::RVNGInputStream *input, const
input->seek(0, librevenge::RVNG_SEEK_SET);
if (!input->isStructured())
return false;
- librevenge::RVNGInputStream *stream = input->getSubStreamByName(name);
+ const RVNGInputStreamPtr_t stream(input->getSubStreamByName(name));
if (!stream)
return false;
- librevenge::RVNGInputStream *relStream = input->getSubStreamByName(getRelationshipsForTarget(name).c_str());
+ const RVNGInputStreamPtr_t relStream(input->getSubStreamByName(getRelationshipsForTarget(name).c_str()));
input->seek(0, librevenge::RVNG_SEEK_SET);
- VSDXRelationships rels(relStream);
- if (relStream)
- delete relStream;
+ VSDXRelationships rels(relStream.get());
rels.rebaseTargets(getTargetBaseDirectory(name).c_str());
- processXmlDocument(stream, rels);
+ processXmlDocument(stream.get(), rels);
- delete stream;
return true;
}
@@ -216,19 +206,16 @@ bool libvisio::VSDXParser::parsePages(librevenge::RVNGInputStream *input, const
input->seek(0, librevenge::RVNG_SEEK_SET);
if (!input->isStructured())
return false;
- librevenge::RVNGInputStream *stream = input->getSubStreamByName(name);
+ const RVNGInputStreamPtr_t stream(input->getSubStreamByName(name));
if (!stream)
return false;
- librevenge::RVNGInputStream *relStream = input->getSubStreamByName(getRelationshipsForTarget(name).c_str());
+ const RVNGInputStreamPtr_t relStream(input->getSubStreamByName(getRelationshipsForTarget(name).c_str()));
input->seek(0, librevenge::RVNG_SEEK_SET);
- VSDXRelationships rels(relStream);
- if (relStream)
- delete relStream;
+ VSDXRelationships rels(relStream.get());
rels.rebaseTargets(getTargetBaseDirectory(name).c_str());
- processXmlDocument(stream, rels);
+ processXmlDocument(stream.get(), rels);
- delete stream;
return true;
}
@@ -239,19 +226,16 @@ bool libvisio::VSDXParser::parsePage(librevenge::RVNGInputStream *input, const c
input->seek(0, librevenge::RVNG_SEEK_SET);
if (!input->isStructured())
return false;
- librevenge::RVNGInputStream *stream = input->getSubStreamByName(name);
+ const RVNGInputStreamPtr_t stream(input->getSubStreamByName(name));
if (!stream)
return false;
- librevenge::RVNGInputStream *relStream = input->getSubStreamByName(getRelationshipsForTarget(name).c_str());
+ const RVNGInputStreamPtr_t relStream(input->getSubStreamByName(getRelationshipsForTarget(name).c_str()));
input->seek(0, librevenge::RVNG_SEEK_SET);
- VSDXRelationships rels(relStream);
- if (relStream)
- delete relStream;
+ VSDXRelationships rels(relStream.get());
rels.rebaseTargets(getTargetBaseDirectory(name).c_str());
- processXmlDocument(stream, rels);
+ processXmlDocument(stream.get(), rels);
- delete stream;
return true;
}
@@ -262,13 +246,12 @@ bool libvisio::VSDXParser::parseTheme(librevenge::RVNGInputStream *input, const
input->seek(0, librevenge::RVNG_SEEK_SET);
if (!input->isStructured())
return false;
- librevenge::RVNGInputStream *stream = input->getSubStreamByName(name);
+ const RVNGInputStreamPtr_t stream(input->getSubStreamByName(name));
if (!stream)
return false;
- m_currentTheme.parse(stream);
+ m_currentTheme.parse(stream.get());
- delete stream;
return true;
}
@@ -286,24 +269,22 @@ bool libvisio::VSDXParser::parseMetaData(librevenge::RVNGInputStream *input, lib
const libvisio::VSDXRelationship *coreProp = rels.getRelationshipByType("http://schemas.openxmlformats.org/package/2006/relationships/metadata/core-properties");
if (coreProp)
{
- librevenge::RVNGInputStream *stream = input->getSubStreamByName(coreProp->getTarget().c_str());
+ const RVNGInputStreamPtr_t stream(input->getSubStreamByName(coreProp->getTarget().c_str()));
if (stream)
{
result = true;
- metaData.parse(stream);
- delete stream;
+ metaData.parse(stream.get());
}
}
const libvisio::VSDXRelationship *extendedProp = rels.getRelationshipByType("http://schemas.openxmlformats.org/officeDocument/2006/relationships/extended-properties");
if (extendedProp)
{
- librevenge::RVNGInputStream *stream = input->getSubStreamByName(extendedProp->getTarget().c_str());
+ const RVNGInputStreamPtr_t stream(input->getSubStreamByName(extendedProp->getTarget().c_str()));
if (stream)
{
result = true;
- metaData.parse(stream);
- delete stream;
+ metaData.parse(stream.get());
}
}
m_collector->collectMetaData(metaData.getMetaData());
@@ -536,7 +517,7 @@ void libvisio::VSDXParser::extractBinaryData(librevenge::RVNGInputStream *input,
if (!input || !input->isStructured())
return;
input->seek(0, librevenge::RVNG_SEEK_SET);
- librevenge::RVNGInputStream *stream = input->getSubStreamByName(name);
+ const RVNGInputStreamPtr_t stream(input->getSubStreamByName(name));
if (!stream)
return;
while (true)
@@ -548,7 +529,6 @@ void libvisio::VSDXParser::extractBinaryData(librevenge::RVNGInputStream *input,
if (stream->isEnd())
break;
}
- delete stream;
VSD_DEBUG_MSG(("%s\n", m_currentBinaryData.getBase64Data().cstr()));
}
commit 6403c07b9d5e420cce2c060c09223f81b2a5c48a
Author: David Tardon <dtardon at redhat.com>
Date: Tue Jul 14 15:41:35 2015 +0200
use shared_ptr for streams
Change-Id: If33a4b0f1f47683412d6696f6d06de9844c5971c
diff --git a/configure.ac b/configure.ac
index 40747e9..00d0f3a 100644
--- a/configure.ac
+++ b/configure.ac
@@ -106,6 +106,7 @@ AC_CHECK_HEADERS(
boost/algorithm/string.hpp \
boost/lexical_cast.hpp \
boost/optional.hpp \
+ boost/shared_ptr.hpp \
boost/spirit/include/classic.hpp,
[],
[AC_MSG_ERROR(Required boost headers not found. install boost >= 1.36)],
diff --git a/src/lib/VSDXParser.cpp b/src/lib/VSDXParser.cpp
index 02a3989..5063507 100644
--- a/src/lib/VSDXParser.cpp
+++ b/src/lib/VSDXParser.cpp
@@ -60,53 +60,46 @@ libvisio::VSDXParser::~VSDXParser()
{
}
-bool libvisio::VSDXParser::parseMain()
+bool libvisio::VSDXParser::parseMain() try
{
if (!m_input || !m_input->isStructured())
return false;
- librevenge::RVNGInputStream *tmpInput = 0;
- try
- {
- tmpInput = m_input->getSubStreamByName("_rels/.rels");
- if (!tmpInput)
- return false;
-
- libvisio::VSDXRelationships rootRels(tmpInput);
- delete tmpInput;
- tmpInput = 0;
+ RVNGInputStreamPtr_t tmpInput;
+ tmpInput.reset(m_input->getSubStreamByName("_rels/.rels"));
+ if (!tmpInput)
+ return false;
- // Check whether the relationship points to a Visio document stream
- const libvisio::VSDXRelationship *rel = rootRels.getRelationshipByType("http://schemas.microsoft.com/visio/2010/relationships/document");
- if (!rel)
- return false;
+ libvisio::VSDXRelationships rootRels(tmpInput.get());
- std::vector<std::map<unsigned, XForm> > groupXFormsSequence;
- std::vector<std::map<unsigned, unsigned> > groupMembershipsSequence;
- std::vector<std::list<unsigned> > documentPageShapeOrders;
+ // Check whether the relationship points to a Visio document stream
+ const libvisio::VSDXRelationship *rel = rootRels.getRelationshipByType("http://schemas.microsoft.com/visio/2010/relationships/document");
+ if (!rel)
+ return false;
- VSDStylesCollector stylesCollector(groupXFormsSequence, groupMembershipsSequence, documentPageShapeOrders);
- m_collector = &stylesCollector;
- if (!parseDocument(m_input, rel->getTarget().c_str()))
- return false;
+ std::vector<std::map<unsigned, XForm> > groupXFormsSequence;
+ std::vector<std::map<unsigned, unsigned> > groupMembershipsSequence;
+ std::vector<std::list<unsigned> > documentPageShapeOrders;
- VSDStyles styles = stylesCollector.getStyleSheets();
+ VSDStylesCollector stylesCollector(groupXFormsSequence, groupMembershipsSequence, documentPageShapeOrders);
+ m_collector = &stylesCollector;
+ if (!parseDocument(m_input, rel->getTarget().c_str()))
+ return false;
- VSDContentCollector contentCollector(m_painter, groupXFormsSequence, groupMembershipsSequence, documentPageShapeOrders, styles, m_stencils);
- m_collector = &contentCollector;
- parseMetaData(m_input, rootRels);
+ VSDStyles styles = stylesCollector.getStyleSheets();
- if (!parseDocument(m_input, rel->getTarget().c_str()))
- return false;
+ VSDContentCollector contentCollector(m_painter, groupXFormsSequence, groupMembershipsSequence, documentPageShapeOrders, styles, m_stencils);
+ m_collector = &contentCollector;
+ parseMetaData(m_input, rootRels);
- return true;
- }
- catch (...)
- {
- if (tmpInput)
- delete tmpInput;
+ if (!parseDocument(m_input, rel->getTarget().c_str()))
return false;
- }
+
+ return true;
+}
+catch (...)
+{
+ return false;
}
bool libvisio::VSDXParser::extractStencils()
diff --git a/src/lib/libvisio_utils.h b/src/lib/libvisio_utils.h
index 0836f4b..0ff3a16 100644
--- a/src/lib/libvisio_utils.h
+++ b/src/lib/libvisio_utils.h
@@ -10,6 +10,8 @@
#ifndef __LIBVISIO_UTILS_H__
#define __LIBVISIO_UTILS_H__
+#include <boost/shared_ptr.hpp>
+
#include "VSDTypes.h"
#ifdef _MSC_VER
@@ -68,6 +70,8 @@ typedef unsigned __int64 uint64_t;
namespace libvisio
{
+typedef boost::shared_ptr<librevenge::RVNGInputStream> RVNGInputStreamPtr_t;
+
uint8_t readU8(librevenge::RVNGInputStream *input);
uint16_t readU16(librevenge::RVNGInputStream *input);
int16_t readS16(librevenge::RVNGInputStream *input);
commit 2496ab82164620a13eca99862b93648bd1c79d03
Author: David Tardon <dtardon at redhat.com>
Date: Tue Jul 14 12:18:28 2015 +0200
avoid double deletion in case of exception
Change-Id: Ic2767a987ab0890f0dc8fd4e087d0c830ff08bfa
diff --git a/src/lib/VSDXParser.cpp b/src/lib/VSDXParser.cpp
index b8669dd..02a3989 100644
--- a/src/lib/VSDXParser.cpp
+++ b/src/lib/VSDXParser.cpp
@@ -74,6 +74,7 @@ bool libvisio::VSDXParser::parseMain()
libvisio::VSDXRelationships rootRels(tmpInput);
delete tmpInput;
+ tmpInput = 0;
// Check whether the relationship points to a Visio document stream
const libvisio::VSDXRelationship *rel = rootRels.getRelationshipByType("http://schemas.microsoft.com/visio/2010/relationships/document");
More information about the Libreoffice-commits
mailing list