From ec6eaa58addf0d8823f8c56d4ec168ff389da8c5 Mon Sep 17 00:00:00 2001 From: Noel Grandin Date: Tue, 5 May 2020 19:10:16 +0200 Subject: fix memory leak of xmlDoc objects in unit tests Change-Id: Id16731bbbe2f1b0e3642722d77aba04fc98db4cc Reviewed-on: https://gerrit.libreoffice.org/c/core/+/93508 Tested-by: Jenkins Reviewed-by: Noel Grandin --- writerperfect/qa/unit/EPUBExportTest.cxx | 17 ++++------------- 1 file changed, 4 insertions(+), 13 deletions(-) (limited to 'writerperfect') diff --git a/writerperfect/qa/unit/EPUBExportTest.cxx b/writerperfect/qa/unit/EPUBExportTest.cxx index cf50d2d9da52..e6ca36fed947 100644 --- a/writerperfect/qa/unit/EPUBExportTest.cxx +++ b/writerperfect/qa/unit/EPUBExportTest.cxx @@ -40,7 +40,7 @@ class EPUBExportTest : public test::BootstrapFixture, protected: uno::Reference mxComponent; utl::TempFile maTempFile; - xmlDocPtr mpXmlDoc = nullptr; + xmlDocUniquePtr mpXmlDoc; uno::Reference mxZipFile; OUString maFilterOptions; @@ -50,7 +50,7 @@ public: void registerNamespaces(xmlXPathContextPtr& pXmlXpathCtx) override; void createDoc(const OUString& rFile, const uno::Sequence& rFilterData); /// Returns an XML representation of the stream named rName in the exported package. - xmlDocPtr parseExport(const OUString& rName); + xmlDocUniquePtr parseExport(const OUString& rName); /// Parses a CSS representation of the stream named rName and returns it. std::map> parseCss(const OUString& rName); /// Looks up a key of a class in rCss. @@ -70,11 +70,7 @@ void EPUBExportTest::tearDown() if (mxComponent.is()) mxComponent->dispose(); - if (mpXmlDoc) - { - xmlFreeDoc(mpXmlDoc); - mpXmlDoc = nullptr; - } + mpXmlDoc.reset(); test::BootstrapFixture::tearDown(); } @@ -108,7 +104,7 @@ void EPUBExportTest::createDoc(const OUString& rFile, = packages::zip::ZipFileAccess::createWithURL(mxComponentContext, maTempFile.GetURL()); } -xmlDocPtr EPUBExportTest::parseExport(const OUString& rName) +xmlDocUniquePtr EPUBExportTest::parseExport(const OUString& rName) { uno::Reference xInputStream(mxZipFile->getByName(rName), uno::UNO_QUERY); std::unique_ptr pStream(utl::UcbStreamHelper::CreateStream(xInputStream, true)); @@ -780,7 +776,6 @@ CPPUNIT_TEST_FIXTURE(EPUBExportTest, testPageSize) assertXPath(mpXmlDoc, "/xhtml:html/xhtml:head/xhtml:meta[@name='viewport']", "content", "width=816, height=1056"); - xmlFreeDoc(mpXmlDoc); mpXmlDoc = parseExport("OEBPS/images/image0001.svg"); // This was 288mm, logic->logic conversion input was a pixel value. assertXPath(mpXmlDoc, "/svg:svg", "width", "216mm"); @@ -835,8 +830,6 @@ CPPUNIT_TEST_FIXTURE(EPUBExportTest, testTdf115623SplitByChapter) OUString aClass = getXPath(mpXmlDoc, "//xhtml:body", "class"); CPPUNIT_ASSERT_EQUAL(OUString("vertical-rl"), EPUBExportTest::getCss(aCssDoc, aClass, "writing-mode")); - xmlFreeDoc(mpXmlDoc); - mpXmlDoc = nullptr; } // Split HTML should keep the same writing-mode. { @@ -857,8 +850,6 @@ CPPUNIT_TEST_FIXTURE(EPUBExportTest, testTdf115623ManyPageSpans) OUString aClass = getXPath(mpXmlDoc, "//xhtml:body", "class"); CPPUNIT_ASSERT_EQUAL(OUString("vertical-rl"), EPUBExportTest::getCss(aCssDoc, aClass, "writing-mode")); - xmlFreeDoc(mpXmlDoc); - mpXmlDoc = nullptr; } { mpXmlDoc = parseExport("OEBPS/sections/section0002.xhtml"); -- cgit