[prev in list] [next in list] [prev in thread] [next in thread] 

List:       kde-commits
Subject:    [okular/KDE/4.13] core: Don't leak temporary unpacked metadata files extracted from .okular files
From:       Fabio D'Urso <fabiodurso () hotmail ! it>
Date:       2014-05-10 9:46:10
Message-ID: E1Wj3r8-0005Yd-L8 () scm ! kde ! org
[Download RAW message or body]

Git commit f7ec9df0af0f15ed9db8200b404c33c0f91fdc22 by Fabio D'Urso.
Committed on 10/05/2014 at 09:35.
Pushed by fabiod into branch 'KDE/4.13'.

Don't leak temporary unpacked metadata files extracted from .okular files

M  +9    -13   core/document.cpp
M  +2    -1    core/document_p.h

http://commits.kde.org/okular/f7ec9df0af0f15ed9db8200b404c33c0f91fdc22

diff --git a/core/document.cpp b/core/document.cpp
index 49f5d7b..ea13386 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 3010428..62bc26d 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;


[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic