Commit 8b64dafc authored by Brad Hards's avatar Brad Hards

Plug a few memory leaks in the Qt4 bindings.

parent 64c07a20
2005-12-28 Brad Hards <bradh@frogmouth.net>
* qt4/src/poppler-private.h (Poppler): delete passwords after we've
initialised the PDFDoc
* qt4/src/poppler-qt4.h: Add warning about deleting the Document
when done.
* qt4/tests/check_*.cpp: Delete the Poppler::Document
and Poppler::Page objects to avoid leaks
* qt4/tests/check_version.cpp: removed, there is a replacement
automated test.
* qt4/tests/poppler-fonts.cpp (main): Delete Poppler::Document on exit
to avoid a memory leak.
* qt4/tests/stress-poppler-qt4.cpp: Delete Poppler::Document and
Poppler::Page objects to avoid leaks.
* qt4/src/poppler-document.cc (Poppler): Delete *doc in
Document::load(), to avoid a memory leak on failure.
Delete font results list, avoid a memory leak
Delete font scanner object, avoid a memory leak
2005-12-27 Brad Hards <bradh@frogmouth.net>
* qt4/src/poppler-qt4.h:
......
......@@ -53,6 +53,7 @@ namespace Poppler {
return pdoc;
}
else
delete doc;
return NULL;
}
......@@ -64,6 +65,7 @@ namespace Poppler {
Document::~Document()
{
delete m_doc->m_fontInfoScanner;
delete m_doc;
}
......@@ -170,6 +172,7 @@ namespace Poppler {
(Poppler::FontInfo::Type)((::FontInfo*)items->get(i))->getType()
));
}
deleteGooList(items, ::FontInfo);
return true;
}
......
......@@ -25,7 +25,12 @@ namespace Poppler {
class DocumentData {
public:
DocumentData(GooString *filePath, GooString *ownerPassword, GooString *userPassword) :
doc(filePath, ownerPassword, userPassword) {}
doc(filePath, ownerPassword, userPassword)
{
// It might be more appropriate to delete these in PDFDoc
delete ownerPassword;
delete userPassword;
}
class PDFDoc doc;
bool locked;
FontInfoScanner *m_fontInfoScanner;
......
......@@ -326,6 +326,9 @@ delete pixmap;
Load the document from a file on disk
\param filePath the name (and path, if required) of the file to load
\warning The application owns the pointer to Document, and this should
be deleted when no longer required.
*/
static Document *Document::load(const QString & filePath,
const QByteArray &ownerPassword=QByteArray(),
......
......@@ -21,6 +21,8 @@ void TestFontsData::checkNoFonts()
QList<Poppler::FontInfo> listOfFonts = doc->fonts();
QCOMPARE( listOfFonts.size(), 0 );
delete doc;
}
void TestFontsData::checkType1()
......@@ -37,6 +39,8 @@ void TestFontsData::checkType1()
QCOMPARE( listOfFonts.at(0).isEmbedded(), false );
QCOMPARE( listOfFonts.at(0).isSubset(), false );
delete doc;
}
void TestFontsData::checkType3()
......@@ -60,6 +64,8 @@ void TestFontsData::checkType3()
QCOMPARE( listOfFonts.at(1).isEmbedded(), true );
QCOMPARE( listOfFonts.at(1).isSubset(), false );
delete doc;
}
void TestFontsData::checkTrueType()
......@@ -83,6 +89,8 @@ void TestFontsData::checkTrueType()
QCOMPARE( listOfFonts.at(1).isEmbedded(), false );
QCOMPARE( listOfFonts.at(1).isSubset(), false );
delete doc;
}
QTEST_MAIN(TestFontsData)
......
......@@ -46,6 +46,8 @@ void TestMetaData::checkStrings()
QFETCH( QString, key );
QFETCH( QString, value );
QCOMPARE( doc->info(key), value );
delete doc;
}
void TestMetaData::checkStrings2_data()
......@@ -71,6 +73,8 @@ void TestMetaData::checkStrings2()
QFETCH( QString, key );
QFETCH( QString, value );
QCOMPARE( doc->info(key), value );
delete doc;
}
void TestMetaData::checkStringKeys()
......@@ -86,6 +90,8 @@ void TestMetaData::checkStringKeys()
QStringList keysInDoc = doc->infoKeys();
keysInDoc.sort();
QCOMPARE( keysInDoc, keyList );
delete doc;
}
void TestMetaData::checkLinearised()
......@@ -96,10 +102,14 @@ void TestMetaData::checkLinearised()
QVERIFY( doc->isLinearized() );
delete doc;
doc = Poppler::Document::load("../../../test/unittestcases/truetype.pdf");
QVERIFY( doc );
QEXPECT_FAIL("", "We don't yet handle linearisation correctly", Continue);
QCOMPARE( doc->isLinearized(), false );
delete doc;
}
void TestMetaData::checkPortraitOrientation()
......@@ -108,7 +118,11 @@ void TestMetaData::checkPortraitOrientation()
doc = Poppler::Document::load("../../../test/unittestcases/orientation.pdf");
QVERIFY( doc );
QCOMPARE( doc->page(0)->orientation(), Poppler::Page::Portrait );
Poppler::Page *page = doc->page(0);
QCOMPARE( page->orientation(), Poppler::Page::Portrait );
delete page;
delete doc;
}
void TestMetaData::checkNumPages()
......@@ -118,9 +132,13 @@ void TestMetaData::checkNumPages()
QVERIFY( doc );
QCOMPARE( doc->numPages(), 2 );
delete doc;
doc = Poppler::Document::load("../../../test/unittestcases/truetype.pdf");
QVERIFY( doc );
QCOMPARE( doc->numPages(), 1 );
delete doc;
}
void TestMetaData::checkDate()
......@@ -131,6 +149,8 @@ void TestMetaData::checkDate()
QVERIFY( doc );
QCOMPARE( doc->date("ModDate"), QDateTime(QDate(2005, 12, 5), QTime(9,44,46), Qt::UTC ) );
QCOMPARE( doc->date("CreationDate"), QDateTime(QDate(2005, 8, 13), QTime(1,12,11), Qt::UTC ) );
delete doc;
}
void TestMetaData::checkPageSize()
......@@ -139,8 +159,12 @@ void TestMetaData::checkPageSize()
doc = Poppler::Document::load("../../../test/unittestcases/truetype.pdf");
QVERIFY( doc );
QCOMPARE( doc->page(0)->pageSize(), QSize(595, 842) );
QCOMPARE( doc->page(0)->pageSizeF(), QSizeF(595.22, 842) );
Poppler::Page *page = doc->page(0);
QCOMPARE( page->pageSize(), QSize(595, 842) );
QCOMPARE( page->pageSizeF(), QSizeF(595.22, 842) );
delete page;
delete doc;
}
......@@ -150,7 +174,11 @@ void TestMetaData::checkLandscapeOrientation()
doc = Poppler::Document::load("../../../test/unittestcases/orientation.pdf");
QVERIFY( doc );
QCOMPARE( doc->page(1)->orientation(), Poppler::Page::Landscape );
Poppler::Page *page = doc->page(1);
QCOMPARE( page->orientation(), Poppler::Page::Landscape );
delete page;
delete doc;
}
void TestMetaData::checkUpsideDownOrientation()
......@@ -159,7 +187,11 @@ void TestMetaData::checkUpsideDownOrientation()
doc = Poppler::Document::load("../../../test/unittestcases/orientation.pdf");
QVERIFY( doc );
QCOMPARE( doc->page(2)->orientation(), Poppler::Page::UpsideDown );
Poppler::Page *page = doc->page(2);
QCOMPARE( page->orientation(), Poppler::Page::UpsideDown );
delete page;
delete doc;
}
void TestMetaData::checkSeascapeOrientation()
......@@ -168,7 +200,11 @@ void TestMetaData::checkSeascapeOrientation()
doc = Poppler::Document::load("../../../test/unittestcases/orientation.pdf");
QVERIFY( doc );
QCOMPARE( doc->page(3)->orientation(), Poppler::Page::Seascape );
Poppler::Page *page = doc->page(3);
QCOMPARE( page->orientation(), Poppler::Page::Seascape );
delete page;
delete doc;
}
void TestMetaData::checkVersion()
......@@ -178,6 +214,8 @@ void TestMetaData::checkVersion()
QVERIFY( doc );
QCOMPARE( doc->pdfVersion(), 1.6 );
delete doc;
}
QTEST_MAIN(TestMetaData)
......
......@@ -19,6 +19,8 @@ void TestPageLayout::checkNone()
QVERIFY( doc );
QCOMPARE( doc->pageLayout(), Poppler::Document::NoLayout );
delete doc;
}
void TestPageLayout::checkSingle()
......@@ -28,6 +30,8 @@ void TestPageLayout::checkSingle()
QVERIFY( doc );
QCOMPARE( doc->pageLayout(), Poppler::Document::SinglePage );
delete doc;
}
void TestPageLayout::checkFacing()
......@@ -37,6 +41,8 @@ void TestPageLayout::checkFacing()
QVERIFY( doc );
QCOMPARE( doc->pageLayout(), Poppler::Document::TwoPageRight );
delete doc;
}
QTEST_MAIN(TestPageLayout)
......
......@@ -21,6 +21,8 @@ void TestPageMode::checkNone()
QVERIFY( doc );
QCOMPARE( doc->pageMode(), Poppler::Document::UseNone );
delete doc;
}
void TestPageMode::checkFullScreen()
......@@ -30,6 +32,8 @@ void TestPageMode::checkFullScreen()
QVERIFY( doc );
QCOMPARE( doc->pageMode(), Poppler::Document::FullScreen );
delete doc;
}
void TestPageMode::checkAttachments()
......@@ -39,6 +43,8 @@ void TestPageMode::checkAttachments()
QVERIFY( doc );
QCOMPARE( doc->pageMode(), Poppler::Document::UseAttach );
delete doc;
}
void TestPageMode::checkThumbs()
......@@ -48,6 +54,8 @@ void TestPageMode::checkThumbs()
QVERIFY( doc );
QCOMPARE( doc->pageMode(), Poppler::Document::UseThumbs );
delete doc;
}
void TestPageMode::checkOC()
......@@ -57,6 +65,8 @@ void TestPageMode::checkOC()
QVERIFY( doc );
QCOMPARE( doc->pageMode(), Poppler::Document::UseOC );
delete doc;
}
QTEST_MAIN(TestPageMode)
......
......@@ -36,6 +36,8 @@ void TestPermissions::permissions1()
// we are allowed to assemble this document
QVERIFY( doc->okToAssemble() );
delete doc;
}
QTEST_MAIN(TestPermissions)
......
#include <QtCore/QtCore>
#define UNSTABLE_POPPLER_QT4
#include <poppler-qt4.h>
int main( int argc, char **argv )
{
QCoreApplication a( argc, argv ); // QApplication required!
Poppler::Document *doc = Poppler::Document::load("../../../test/unittestcases/doublepage.pdf");
if (!doc)
{
exit(1);
}
if ( !(doc->pdfVersion() == 1.6 ) )
{
exit(1);
}
exit(0);
}
......@@ -71,4 +71,5 @@ int main( int argc, char **argv )
}
std::cout << std::endl;
}
delete doc;
}
......@@ -57,10 +57,12 @@ int main( int argc, char **argv )
page->renderToPixmap(pixmap);
page->pageSize();
page->orientation();
delete page;
std::cout << ".";
std::cout.flush();
}
std::cout << std::endl;
delete doc;
}
}
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment