From 612776e7976f1a901849c61ae9142dd49b8e3f5c Mon Sep 17 00:00:00 2001 From: Arno Date: Sat, 14 Sep 2013 13:01:21 +0200 Subject: Behave on qApp->quit() Sometimes there was a warning that a thread was being destroyed while still running. This was SmDirWatcher::run(). read() blocks until new data is ready, so run() never exited. Fix it by poll()ing the inotify_descriptor. Return immediately if no data is ready. Also fix a small memory leak. Delete ConsistencyChecker when the dialog is destructed. --- consistencycheck.cpp | 4 ++++ consistencycheck.h | 1 + smdirmodel.cpp | 1 + smdirwatcher.cpp | 10 ++++++++++ 4 files changed, 16 insertions(+) diff --git a/consistencycheck.cpp b/consistencycheck.cpp index 7e463a2..1583093 100644 --- a/consistencycheck.cpp +++ b/consistencycheck.cpp @@ -101,6 +101,10 @@ ConsistencyCheck::ConsistencyCheck(QWidget *parent, Qt::WindowFlags f) : SmDialo setMinimumWidth(600); } +ConsistencyCheck::~ConsistencyCheck(){ + mChecker->deleteLater(); +} + void ConsistencyCheck::setProgressBarMax(int max){ mProgress->reset(); mProgress->setMaximum(max); diff --git a/consistencycheck.h b/consistencycheck.h index ca078f1..6f54dcb 100644 --- a/consistencycheck.h +++ b/consistencycheck.h @@ -30,6 +30,7 @@ class ConsistencyCheck : public SmDialog { public: enum Mode { DbCheck, FsCheck }; explicit ConsistencyCheck(QWidget *parent = 0, Qt::WindowFlags f = 0); + ~ConsistencyCheck(); public slots: void setProgressBarMax(int max); diff --git a/smdirmodel.cpp b/smdirmodel.cpp index 8a403d1..2b1e7dc 100644 --- a/smdirmodel.cpp +++ b/smdirmodel.cpp @@ -38,6 +38,7 @@ SmDirModel::~SmDirModel(){ if(mWatch->isRunning()){ mWatch->stop(); } + mWatch->deleteLater(); } QVariant SmDirModel::data(const QModelIndex &index, int role) const{ diff --git a/smdirwatcher.cpp b/smdirwatcher.cpp index 038c4cf..5b4f42a 100644 --- a/smdirwatcher.cpp +++ b/smdirwatcher.cpp @@ -11,6 +11,7 @@ #include #include +#include #include "smdirmodel.h" #include "smdirwatcher.h" @@ -116,6 +117,14 @@ QList SmDirWatcher::generalData(const QString &path){ } void SmDirWatcher::run(){ + struct pollfd pfd[1]; + pfd[0].fd = mFd; + pfd[0].events = POLLIN; + pfd[0].revents = 0; + int pr = poll(pfd, 1, 0); + if(pr <= 0){ + return; + } int r = read(mFd, mINdata, mBufLen); if(r <= 0){ return; @@ -145,6 +154,7 @@ void SmDirWatcher::run(){ void SmDirWatcher::stop(){ quit(); + wait(); } AsyncTask::AsyncTask(const QString &path) : mSkip(false), mPath(path) {} -- cgit v1.2.3-70-g09d2