Propagator: Attempt to fix a crash in OwncloudPropagator::scheduleNextJob
authorOlivier Goffart <ogoffart@woboq.com>
Thu, 9 Mar 2017 08:41:36 +0000 (09:41 +0100)
committerOlivier Goffart <olivier@woboq.com>
Thu, 9 Mar 2017 14:48:52 +0000 (15:48 +0100)
The crash reporter shows many crashes in OwncloudPropagator::scheduleNextJob.
We don't really know what could be the cause, but it's probably because
the _activeJobList contains dangling pointer.
So this patch makes sure to remove all the jobs from this list as they get
destroyed.

src/libsync/owncloudpropagator.cpp
src/libsync/owncloudpropagator.h

index e2c910213ffafa75358b77e3b14ec7671d4a0ccc..af584b091e9089cf6910f9e990f97ab3566a835d 100644 (file)
@@ -94,6 +94,16 @@ int OwncloudPropagator::hardMaximumActiveJob()
     return max;
 }
 
+PropagateItemJob::~PropagateItemJob()
+{
+    if (auto p = propagator()) {
+        // Normally, every job should clean itself from the _activeJobList. So this should not be
+        // needed. But if a job has a bug or is deleted before the network jobs signal get received,
+        // we might risk end up with dangling pointer in the list which may cause crashes.
+        p->_activeJobList.removeAll(this);
+    }
+}
+
 /** Updates, creates or removes a blacklist entry for the given item.
  *
  * Returns whether the error should be suppressed.
index ef5db3b1e72a1bef1139a743a99223cc2f0d68f0..e16e2aee5370b7dba502999365aaa9c24e782206 100644 (file)
@@ -160,6 +160,7 @@ private:
 public:
     PropagateItemJob(OwncloudPropagator* propagator, const SyncFileItemPtr &item)
         : PropagatorJob(propagator), _item(item) {}
+    ~PropagateItemJob();
 
     bool scheduleNextJob() Q_DECL_OVERRIDE {
         if (_state != NotYetStarted) {