FilePath object is also deleted when deleting a MediaImageContainer
authorMikko Keinänen <mikko.keinanen@gmail.com>
Sat, 9 Oct 2010 16:01:02 +0000 (19:01 +0300)
committerMikko Keinänen <mikko.keinanen@gmail.com>
Sat, 9 Oct 2010 16:01:02 +0000 (19:01 +0300)
object.

src/dataobjects/mediaimagecontainer.cpp
src/dataobjects/mediaimagecontainer.h
src/emulauncher.cpp
src/utils/fileutil.cpp

index cfde86b..a394114 100644 (file)
@@ -43,9 +43,7 @@ MediaImageContainer::MediaImageContainer(QString name, QString checksum,
 MediaImageContainer::~MediaImageContainer()
 {
     qDeleteAll(lstMediaImage);
-    //delete setup;
-    //delete filePath; // NOTE: this filePath object is shared resource and cannot be deleted here!
-                    // take care of the deletion where created!!!
+    delete filePath;
 }
 
 MediaImageContainer::MediaImageContainer(MediaImageContainer &mic)
index 6d2f1e6..5c51307 100644 (file)
@@ -30,9 +30,9 @@ class MediaImageContainer : public EmuFrontFile
 public:
     MediaImageContainer();
     MediaImageContainer(int id, QString name, QString checksum,
-        int size, QList<MediaImage*> images/*, Setup *setup*/, FilePathObject *fpo);
+        int size, QList<MediaImage*> images, FilePathObject *fpo);
     MediaImageContainer(QString name, QString checksum,
-        int size, QList<MediaImage*> images/*, Setup *setup*/, FilePathObject *fpo);
+        int size, QList<MediaImage*> images, FilePathObject *fpo);
     ~MediaImageContainer();
     MediaImageContainer(MediaImageContainer&);
     MediaImageContainer& operator=(MediaImageContainer&);
@@ -40,13 +40,10 @@ public:
     void setMediaImages(QList<MediaImage*>);
     void addMediaImage(MediaImage*);
     void clearMediaImages();
-    /*void setSetup(Setup *);
-    Setup* getSetup() const;*/
     void setFilePath(FilePathObject*);
     FilePathObject* getFilePath() const;
 private:
     QList<MediaImage*> lstMediaImage;
-    //Setup *setup;
     FilePathObject *filePath;
 };
 
index 1ac4964..90a6107 100644 (file)
@@ -187,6 +187,9 @@ void EmuLauncher::launch(const Executable * ex, const MediaImageContainer * mic)
     // TODO: command parameters and assigning multiple media images
     cmdWithParams.append(" \"/tmp/").append(mic->getMediaImages().first()->getName()).append("\"");
     qDebug() << "Command with params " << cmdWithParams;
+    // Executable and MediaImageContainer objects are no more needed:
+    delete ex;
+    delete mic;
     if (!proc) proc = new QProcess(this); // This has to be done in the heap
     proc->start(cmdWithParams, QIODevice::ReadOnly);
 }
index 2df70b4..b537294 100644 (file)
@@ -20,6 +20,7 @@ FileUtil::~FileUtil()
     delete[] buf;
 }
 
+/* Throws EmuFrontException */
 QList<MediaImageContainer*> FileUtil::scanFilePath(FilePathObject *fp, QStringList filters)
 {
     if (!fp->getSetup()){
@@ -65,14 +66,7 @@ QList<MediaImageContainer*> FileUtil::scanFilePath(FilePathObject *fp, QStringLi
                     QString("%1").arg(crc, 0, 16),
                     fileInfo.size(),
                     files,
-                    // TODO: is it guaranteed, that the file path object containing the setup object remains alive
-                    // the whole lifecycle of (this) media image container object?
-                    // * if we assign a copy of the setup object -> waste of memory and time
-                    // * this function is designed to be used from media image path main dialog
-                    //   where we can ensure the lifecycle of file path object -> maybe move the implementation there!?
-                    // TODO: Ensure this! We really need a reference instead of 1000s of copies of setup object!!!
-                    //fp->getSetup(),
-                    fp
+                    new FilePathObject(*fp)
                 );
             containers.append(con);
             qDebug() << "We have " << containers.size() << " containers.";