diff options
author | Albert Astals Cid <aacid@kde.org> | 2011-02-08 19:58:31 +0000 |
---|---|---|
committer | Albert Astals Cid <aacid@kde.org> | 2011-02-08 20:00:37 +0000 |
commit | 77e3d9ce9795b00fbe04cf5d42005d400bc10b6d (patch) | |
tree | fd1bc528fe15f4b874adabbc9fabf9a87cc1f236 | |
parent | fa5fddd6176725fdae02a500c6955dafe993941e (diff) |
Make really sure the uMap static pointer is valid
It might happen you are extremely unlucky and get the same globalParams after a new delete/creation
-rw-r--r-- | qt4/src/poppler-private.cc | 51 | ||||
-rw-r--r-- | qt4/src/poppler-private.h | 34 |
2 files changed, 47 insertions, 38 deletions
diff --git a/qt4/src/poppler-private.cc b/qt4/src/poppler-private.cc index 253222ec..d6e3265d 100644 --- a/qt4/src/poppler-private.cc +++ b/qt4/src/poppler-private.cc @@ -45,6 +45,8 @@ namespace Debug { } + static UnicodeMap *utf8Map = 0; + void setDebugErrorFunction(PopplerDebugFunc function, const QVariant &closure) { Debug::debugFunction = function ? function : Debug::qDebugDebugFunction; @@ -70,14 +72,11 @@ namespace Debug { } QString unicodeToQString(Unicode* u, int len) { - static UnicodeMap *uMap = 0; - static GlobalParams *gParams = globalParams; - if (!uMap || gParams != globalParams) + if (!utf8Map) { GooString enc("UTF-8"); - uMap = globalParams->getUnicodeMap(&enc); - uMap->incRefCnt(); - gParams = globalParams; + utf8Map = globalParams->getUnicodeMap(&enc); + utf8Map->incRefCnt(); } // ignore the last character if it is 0x0 @@ -90,7 +89,7 @@ namespace Debug { for (int i = 0; i < len; ++i) { char buf[8]; - const int n = uMap->mapUnicode(u[i], buf, sizeof(buf)); + const int n = utf8Map->mapUnicode(u[i], buf, sizeof(buf)); convertedStr.append(buf, n); } @@ -223,6 +222,44 @@ namespace Debug { default: ; } } + + DocumentData::~DocumentData() + { + qDeleteAll(m_embeddedFiles); + delete (OptContentModel *)m_optContentModel; + delete doc; + delete m_outputDev; + delete m_fontInfoIterator; + + count --; + if ( count == 0 ) + { + utf8Map = 0; + delete globalParams; + } + } + + void DocumentData::init(GooString *ownerPassword, GooString *userPassword) + { + m_fontInfoIterator = 0; + m_backend = Document::SplashBackend; + m_outputDev = 0; + paperColor = Qt::white; + m_hints = 0; + m_optContentModel = 0; + // It might be more appropriate to delete these in PDFDoc + delete ownerPassword; + delete userPassword; + + if ( count == 0 ) + { + utf8Map = 0; + globalParams = new GlobalParams(); + setErrorFunction(qt4ErrorFunction); + } + count ++; + } + void DocumentData::addTocChildren( QDomDocument * docSyn, QDomNode * parent, GooList * items ) { diff --git a/qt4/src/poppler-private.h b/qt4/src/poppler-private.h index f148dbc7..aebdc4a8 100644 --- a/qt4/src/poppler-private.h +++ b/qt4/src/poppler-private.h @@ -1,7 +1,7 @@ /* poppler-private.h: qt interface to poppler * Copyright (C) 2005, Net Integration Technologies, Inc. * Copyright (C) 2005, 2008, Brad Hards <bradh@frogmouth.net> - * Copyright (C) 2006-2009 by Albert Astals Cid <aacid@kde.org> + * Copyright (C) 2006-2009, 2011 by Albert Astals Cid <aacid@kde.org> * Copyright (C) 2007-2009 by Pino Toscano <pino@kde.org> * Inspired on code by * Copyright (C) 2004 by Albert Astals Cid <tsdgeos@terra.es> @@ -89,37 +89,9 @@ namespace Poppler { init(ownerPassword, userPassword); } - void init(GooString *ownerPassword, GooString *userPassword) - { - m_fontInfoIterator = 0; - m_backend = Document::SplashBackend; - m_outputDev = 0; - paperColor = Qt::white; - m_hints = 0; - m_optContentModel = 0; - // It might be more appropriate to delete these in PDFDoc - delete ownerPassword; - delete userPassword; - - if ( count == 0 ) - { - globalParams = new GlobalParams(); - setErrorFunction(qt4ErrorFunction); - } - count ++; - } + void init(GooString *ownerPassword, GooString *userPassword); - ~DocumentData() - { - qDeleteAll(m_embeddedFiles); - delete (OptContentModel *)m_optContentModel; - delete doc; - delete m_outputDev; - delete m_fontInfoIterator; - - count --; - if ( count == 0 ) delete globalParams; - } + ~DocumentData(); OutputDev *getOutputDev() { |