Created temporary data object was not deleted.
authorMikko Keinänen <mikko.keinanen@gmail.com>
Thu, 21 Oct 2010 21:55:38 +0000 (00:55 +0300)
committerMikko Keinänen <mikko.keinanen@gmail.com>
Thu, 21 Oct 2010 21:55:38 +0000 (00:55 +0300)
src/db/dbmediaimagecontainer.cpp

index e1f11c3..dd116d0 100644 (file)
@@ -48,18 +48,27 @@ int DbMediaImageContainer::insertDataObjectToModel(const EmuFrontObject *efo)
     const MediaImageContainer *mic
         = dynamic_cast<const MediaImageContainer *>(efo);
 
+    if (!mic->getFilePath())
+        throw new EmuFrontException("Cannot install media image "
+            "container to database without a file path object!");
+
     // check if this media image container is already in the database
+
+    // Two possible solutions:
+    // * multiple media image containers with matching checksum will not be stored at all
+    //   (only the first instance will be stored)
+    // * multiple media image containers with matching checksum will be stored
+    //   if each instance is in a different file path
+
     EmuFrontObject *o = getFileByChecksum(mic->getCheckSum());
     int fileId = o ? o->getId() : -1;
-    /*int fileId = getMediaImageContainer(mic->getCheckSum());*/
     if (fileId >= 0) {
+        // ok, we have a matching file, we could still create a new media image instance to the database
         qDebug() << "Media image container already in db with id " << fileId << ".";
+        delete o;
         return fileId;
    }
 
-    if (!mic->getFilePath())
-        throw new EmuFrontException("Cannot install media image "
-            "container to database without a file path object!");
 
     QMap<QString, EmuFrontObject*> images = mic->getMediaImages();
     QList<int> ids = dbMediaImage->storeMediaImages(images);