From f7ec9df0af0f15ed9db8200b404c33c0f91fdc22 Mon Sep 17 00:00:00 2001 From: Fabio D'Urso Date: Sat, 10 May 2014 11:35:33 +0200 Subject: [PATCH] Don't leak temporary unpacked metadata files extracted from .okular files --- core/document.cpp | 22 +++++++++------------- core/document_p.h | 3 ++- 2 files changed, 11 insertions(+), 14 deletions(-) diff --git a/core/document.cpp b/core/document.cpp index 49f5d7b04..ea133864b 100644 --- a/core/document.cpp +++ b/core/document.cpp @@ -109,7 +109,7 @@ struct ArchiveData } KTemporaryFile document; - QString metadataFileName; + KTemporaryFile metadataFile; }; struct RunningSearch @@ -613,12 +613,12 @@ void DocumentPrivate::loadDocumentInfo() if ( m_xmlFileName.isEmpty() ) return; - loadDocumentInfo( m_xmlFileName ); + QFile infoFile( m_xmlFileName ); + loadDocumentInfo( infoFile ); } -void DocumentPrivate::loadDocumentInfo( const QString &fileName ) +void DocumentPrivate::loadDocumentInfo( QFile &infoFile ) { - QFile infoFile( fileName ); if ( !infoFile.exists() || !infoFile.open( QIODevice::ReadOnly ) ) return; @@ -2263,7 +2263,7 @@ bool Document::openDocument( const QString & docFile, const KUrl& url, const KMi // 2. load Additional Data (bookmarks, local annotations and metadata) about the document if ( d->m_archiveData ) { - d->loadDocumentInfo( d->m_archiveData->metadataFileName ); + d->loadDocumentInfo( d->m_archiveData->metadataFile ); d->m_annotationsNeedSaveAs = true; } else @@ -4192,19 +4192,15 @@ bool Document::openDocumentArchive( const QString & docFile, const KUrl & url ) archiveData->document.close(); } - std::auto_ptr< KTemporaryFile > tempMetadataFileName; const KArchiveEntry * metadataEntry = mainDir->entry( metadataFileName ); if ( metadataEntry && metadataEntry->isFile() ) { std::auto_ptr< QIODevice > metadataEntryDevice( static_cast< const KZipFileEntry * >( metadataEntry )->createDevice() ); - tempMetadataFileName.reset( new KTemporaryFile() ); - tempMetadataFileName->setSuffix( ".xml" ); - tempMetadataFileName->setAutoRemove( false ); - if ( tempMetadataFileName->open() ) + archiveData->metadataFile.setSuffix( ".xml" ); + if ( archiveData->metadataFile.open() ) { - copyQIODevice( metadataEntryDevice.get(), tempMetadataFileName.get() ); - archiveData->metadataFileName = tempMetadataFileName->fileName(); - tempMetadataFileName->close(); + copyQIODevice( metadataEntryDevice.get(), &archiveData->metadataFile ); + archiveData->metadataFile.close(); } } diff --git a/core/document_p.h b/core/document_p.h index 3010428dc..62bc26dfa 100644 --- a/core/document_p.h +++ b/core/document_p.h @@ -29,6 +29,7 @@ class QUndoStack; class QEventLoop; +class QFile; class QTimer; class KTemporaryFile; @@ -121,7 +122,7 @@ class DocumentPrivate qulonglong getTotalMemory(); qulonglong getFreeMemory( qulonglong *freeSwap = 0 ); void loadDocumentInfo(); - void loadDocumentInfo( const QString &fileName ); + void loadDocumentInfo( QFile &infoFile ); void loadViewsInfo( View *view, const QDomElement &e ); void saveViewsInfo( View *view, QDomElement &e ) const; QString giveAbsolutePath( const QString & fileName ) const;