[Nepomuk] [nepomuk-core/KDE/4.11] services/storage/backup: BackupManager: Manually delete the backup job

Vishesh Handa me at vhanda.in
Wed Aug 7 07:49:21 UTC 2013


Git commit 96f457b01c01be54637478c4b1433e8b602fd1bd by Vishesh Handa.
Committed on 24/07/2013 at 16:14.
Pushed by vhanda into branch 'KDE/4.11'.

BackupManager: Manually delete the backup job

The backup job is run in a separate thread, and when the job completes
the thread is told to quit and then delete itself. Therefore, based on
the timing two posibilities can occur, and the job finished signal is
queued in the main event loop.

1. The backup thread is deleted, and therefore the backup job never gets
deleted (since its eventloop has been deleted) -> Memory Leak

2. A crash since the job has been deleted and then the slotBackupDone
function tries to access its members.

This was the reason the backup test was occasionally failing.

Edit: No. This doesn't fix the crash. It in fact makes it crash
reliably when running the backup test. For now I'm not deleting the job.
This introduced a small memory leak, but that is better than a crash. We
do not want the backup process to ever crash because it is used in the
migration process.

@Simeon: Could you please take a look at the crash? Run the backuptest
tagsAndRatings to reliably reproduce it. You'll have to uncomment the
// delete job.

CCMAIL: nepomuk at kde.org

M  +5    -0    services/storage/backup/backupmanager.cpp

http://commits.kde.org/nepomuk-core/96f457b01c01be54637478c4b1433e8b602fd1bd

diff --git a/services/storage/backup/backupmanager.cpp b/services/storage/backup/backupmanager.cpp
index a15e104..60ce815 100644
--- a/services/storage/backup/backupmanager.cpp
+++ b/services/storage/backup/backupmanager.cpp
@@ -89,6 +89,7 @@ void Nepomuk2::BackupManager::backup(const QString& oldUrl)
 
     QThread* backupThread = new QThread( this );
     job->moveToThread( backupThread );
+    job->setAutoDelete(false);
     backupThread->start();
 
     connect( job, SIGNAL(finished(KJob*)), backupThread, SLOT(quit()), Qt::QueuedConnection );
@@ -115,6 +116,7 @@ void Nepomuk2::BackupManager::backupTagsAndRatings(const QString& oldUrl)
 
     QThread* backupThread = new QThread( this );
     job->moveToThread( backupThread );
+    job->setAutoDelete(false);
     backupThread->start();
 
     connect( job, SIGNAL(finished(KJob*)), backupThread, SLOT(quit()), Qt::QueuedConnection );
@@ -238,6 +240,9 @@ void Nepomuk2::BackupManager::slotBackupDone(KJob* job)
     else {
         emit backupError(job->errorString());
     }
+
+// FIXME: This causes a reliable crash! Why!
+//    delete job;
 }
 
 void Nepomuk2::BackupManager::slotBackupPercent(KJob*, ulong percent)


More information about the Nepomuk mailing list