[prev in list] [next in list] [prev in thread] [next in thread]
List: kde-commits
Subject: KDE/kdelibs/kdecore
From: Aurélien Gâteau <agateau () kde ! org>
Date: 2010-12-06 9:57:40
Message-ID: 20101206095740.4D74CAC8A4 () svn ! kde ! org
[Download RAW message or body]
SVN commit 1204111 by gateau:
Do not crash if an job was deleted in a slot connected to result()
Note that an assert will trigger if the job is in autoDelete() mode.
M +12 -1 jobs/kjob.cpp
M +18 -0 tests/kjobtest.cpp
M +2 -0 tests/kjobtest.h
--- trunk/KDE/kdelibs/kdecore/jobs/kjob.cpp #1204110:1204111
@@ -24,11 +24,13 @@
#include "kjobuidelegate.h"
+#include <kdebug.h>
#include <kglobal.h>
#include <QEventLoop>
#include <QMap>
#include <QMetaType>
#include <QTimer>
+#include <QWeakPointer>
bool KJobPrivate::_k_kjobUnitEnumRegistered = false;
KJobPrivate::KJobPrivate()
@@ -302,6 +304,9 @@
Q_D(KJob);
d->isFinished = true;
+ bool autoDelete = isAutoDelete();
+ QWeakPointer<KJob> guard(this);
+
if ( d->eventLoop ) {
d->eventLoop->quit();
}
@@ -311,9 +316,15 @@
emit result( this );
- if ( isAutoDelete() )
+ if ( autoDelete ) {
+ Q_ASSERT( guard.data() );
+ if ( guard.data() ) {
deleteLater();
+ } else {
+ kWarning() << "Job was marked as autoDelete() but has already been deleted!";
}
+ }
+}
void KJob::emitPercent( qulonglong processedAmount, qulonglong totalAmount )
{
--- trunk/KDE/kdelibs/kdecore/tests/kjobtest.cpp #1204110:1204111
@@ -303,6 +303,24 @@
m_outerJob->exec();
}
+void KJobTest::testDeletedInResult()
+{
+ TestJob *job = new TestJob;
+ job->setAutoDelete( false );
+
+ connect( job, SIGNAL( result( KJob* ) ),
+ this, SLOT( deleteJob( KJob* ) ) );
+
+ job->start();
+ loop.exec();
+}
+
+void KJobTest::deleteJob(KJob *job)
+{
+ delete job;
+ loop.quit();
+}
+
void KJobTest::slotStartInnerJob()
{
QTimer::singleShot( 100, this, SLOT( slotFinishOuterJob() ) );
--- trunk/KDE/kdelibs/kdecore/tests/kjobtest.h #1204110:1204111
@@ -79,9 +79,11 @@
void testKill();
void testDelegateUsage();
void testNestedExec();
+ void testDeletedInResult();
void slotResult( KJob *job );
void slotFinished(KJob *job);
+ void deleteJob(KJob *);
private:
QEventLoop loop;
[prev in list] [next in list] [prev in thread] [next in thread]
Configure |
About |
News |
Add a list |
Sponsored by KoreLogic