[Marble-commits] KDE/kdeedu/marble/src/lib

Patrick Spendrin ps_ml at gmx.de
Tue Jul 21 00:16:14 CEST 2009


SVN commit 1000144 by sengels:

remove the memory leak without transferring ownership of the PlacemarkContainer

 M  +28 -26    PlacemarkLoader.cpp  
 M  +5 -4      PlacemarkLoader.h  
 M  +0 -2      PlacemarkManager.cpp  


--- trunk/KDE/kdeedu/marble/src/lib/PlacemarkLoader.cpp #1000143:1000144
@@ -33,7 +33,8 @@
       m_filepath( file ),
       m_contents( QString() ),
       m_finalize( finalize ),
-      m_document( 0 )
+      m_document( 0 ),
+      m_container( 0 )
 {
 }
 
@@ -42,12 +43,14 @@
       m_filepath( file ), 
       m_contents( contents ),
       m_finalize( finalize ),
-      m_document( 0 )
+      m_document( 0 ),
+      m_container( 0 )
 {
 }
 
 PlacemarkLoader::~PlacemarkLoader()
 {
+    delete m_container;
     delete m_document;
 }
 
@@ -63,7 +66,7 @@
         QString defaultsrcname;
         QString defaulthomecache;
 
-        PlacemarkContainer *container = new PlacemarkContainer( m_filepath );
+        m_container = new PlacemarkContainer( m_filepath );
     
         if( m_filepath.endsWith(".kml") ) {
             m_filepath.remove(QRegExp("\\.kml$"));
@@ -109,9 +112,9 @@
             bool loadok = false;
 
             if ( !cacheoutdated ) {
-                loadok = loadFile( defaultcachename, container );
+                loadok = loadFile( defaultcachename );
                 if ( loadok )
-                    emit placemarksLoaded( this, container );
+                    emit placemarksLoaded( this, m_container );
             }
             qDebug() << "Loading ended" << loadok;
             if ( loadok ) {
@@ -125,35 +128,34 @@
         if ( QFile::exists( defaultsrcname ) ) {
 
             // Read the KML file.
-            importKml( defaultsrcname, container );
+            importKml( defaultsrcname );
 
-            qDebug() << "ContainerSize for" << m_filepath << ":" << container->size();
+            qDebug() << "ContainerSize for" << m_filepath << ":" << m_container->size();
             // Save the contents in the efficient cache format.
-            saveFile( defaulthomecache, container );
+            saveFile( defaulthomecache );
 
             qDebug() << "placemarksLoaded";
 
             // ...and finally add it to the PlacemarkContainer
-            emit placemarksLoaded( this, container );
+            emit placemarksLoaded( this, m_container );
         }
         else {
             qDebug() << "No Default Placemark Source File for " << m_filepath;
             emit placemarkLoaderFailed( this );
         }
     } else {
-        PlacemarkContainer *container = new PlacemarkContainer( m_filepath );
+        m_container = new PlacemarkContainer( m_filepath );
 
         // Read the KML Data
-        importKmlFromData( container );
+        importKmlFromData();
 
-        emit placemarksLoaded( this, container );
+        emit placemarksLoaded( this, m_container );
     }
 }
 
 const quint32 MarbleMagicNumber = 0x31415926;
 
-void PlacemarkLoader::importKml( const QString& filename,
-                                 PlacemarkContainer* placemarkContainer )
+void PlacemarkLoader::importKml( const QString& filename )
 {
     GeoDataParser parser( GeoData_KML );
 
@@ -175,9 +177,10 @@
 
     m_document = static_cast<GeoDataDocument*>( document );
     m_document->setFileName( m_filepath );
-    *placemarkContainer = PlacemarkContainer( m_document->placemarks(), 
-                                              m_filepath );
 
+    m_container = new PlacemarkContainer( m_document->placemarks(), 
+                                          m_filepath );
+
     file.close();
 
     qDebug() << "newGeoDataDocumentAdded" << m_filepath;
@@ -185,7 +188,7 @@
     emit newGeoDataDocumentAdded( m_document );
 }
 
-void PlacemarkLoader::importKmlFromData( PlacemarkContainer* placemarkContainer )
+void PlacemarkLoader::importKmlFromData()
 {
     GeoDataParser parser( GeoData_KML );
 
@@ -202,9 +205,10 @@
 
     m_document = static_cast<GeoDataDocument*>( document );
     m_document->setFileName( m_filepath );
-    *placemarkContainer = PlacemarkContainer( m_document->placemarks(), 
-                                              m_filepath );
 
+    m_container = new PlacemarkContainer( m_document->placemarks(), 
+                                          m_filepath );
+
     buffer.close();
 
     qDebug() << "newGeoDataDocumentAdded" << m_filepath;
@@ -212,8 +216,7 @@
     emit newGeoDataDocumentAdded( m_document );
 }
 
-void PlacemarkLoader::saveFile( const QString& filename,
-                                 PlacemarkContainer* placemarkContainer )
+void PlacemarkLoader::saveFile( const QString& filename )
 {
     if ( !QDir( MarbleDirs::localPath() + "/placemarks/" ).exists() )
         ( QDir::root() ).mkpath( MarbleDirs::localPath() + "/placemarks/" );
@@ -233,8 +236,8 @@
     qreal lat;
     qreal alt;
 
-    PlacemarkContainer::const_iterator it = placemarkContainer->constBegin();
-    PlacemarkContainer::const_iterator const end = placemarkContainer->constEnd();
+    PlacemarkContainer::const_iterator it = m_container->constBegin();
+    PlacemarkContainer::const_iterator const end = m_container->constEnd();
     for (; it != end; ++it )
     {
         out << (*it).name();
@@ -255,8 +258,7 @@
     return m_finalize;
 }
 
-bool PlacemarkLoader::loadFile( const QString& filename,
-                                 PlacemarkContainer* placemarkContainer )
+bool PlacemarkLoader::loadFile( const QString& filename )
 {
     QFile file( filename );
     file.open( QIODevice::ReadOnly );
@@ -316,7 +318,7 @@
         in >> tmpint64;
         mark.setPopulation( tmpint64 );
 
-        placemarkContainer->append( mark );
+        m_container->append( mark );
         m_document->append( mark );
     }
 
--- trunk/KDE/kdeedu/marble/src/lib/PlacemarkLoader.h #1000143:1000144
@@ -34,15 +34,16 @@
         void placemarkLoaderFailed( PlacemarkLoader* );
         void newGeoDataDocumentAdded( GeoDataDocument* );
     private:
-        bool loadFile( const QString& filename, PlacemarkContainer* placemarkContainer );
-        void saveFile( const QString& filename, PlacemarkContainer* placemarkContainer );
-        void importKml( const QString& filename, PlacemarkContainer* placemarkContainer );
-        void importKmlFromData( PlacemarkContainer* placemarkContainer );
+        bool loadFile( const QString& filename );
+        void saveFile( const QString& filename );
+        void importKml( const QString& filename );
+        void importKmlFromData();
 
         QString m_filepath;
         QString m_contents;
         bool m_finalize;
         GeoDataDocument *m_document;
+        PlacemarkContainer *m_container;
 };
 
 } // namespace Marble
--- trunk/KDE/kdeedu/marble/src/lib/PlacemarkManager.cpp #1000143:1000144
@@ -198,8 +198,6 @@
     if ( container )
     { 
         d->m_model->addPlacemarks( *container, false, d->m_finalized && d->m_loaderList.isEmpty() );
-        delete container;
-        container = 0;
     }
 
     if( d->m_loaderList.isEmpty() ) {


More information about the Marble-commits mailing list