diff options
author | Michal Labedzki <michal.labedzki@tieto.com> | 2015-03-16 14:51:44 +0100 |
---|---|---|
committer | Anders Broman <a.broman58@gmail.com> | 2015-03-18 08:51:55 +0000 |
commit | e6f3da96f8976c2808bd9973b420a76ecfca08f4 (patch) | |
tree | 2d5a3fae9f277fbd5a908a8f6d6d826b567798b8 | |
parent | dfc0689205e6ce0f3ca004a119c51efb80d8cdbb (diff) | |
download | wireshark-e6f3da96f8976c2808bd9973b420a76ecfca08f4.tar.gz |
Qt: Fix recent files threads
Fix crash and memory leak. Please not that
Recent File Status objects and threads still
continously grow and shrink memory usage, but do not
grow continuously.
Bug: 10893
Change-Id: Icc8b7fefd6572b902ac81d22e5f7b16e304fcf16
Reviewed-on: https://code.wireshark.org/review/7699
Petri-Dish: Michal Labedzki <michal.labedzki@tieto.com>
Reviewed-by: Gerald Combs <gerald@wireshark.org>
Tested-by: Petri Dish Buildbot <buildbot-no-reply@wireshark.org>
Reviewed-by: Anders Broman <a.broman58@gmail.com>
-rw-r--r-- | ui/qt/recent_file_status.cpp | 24 | ||||
-rw-r--r-- | ui/qt/recent_file_status.h | 25 | ||||
-rw-r--r-- | ui/qt/wireshark_application.cpp | 15 |
3 files changed, 24 insertions, 40 deletions
diff --git a/ui/qt/recent_file_status.cpp b/ui/qt/recent_file_status.cpp index c30574f0db..1e89017f53 100644 --- a/ui/qt/recent_file_status.cpp +++ b/ui/qt/recent_file_status.cpp @@ -21,22 +21,20 @@ #include "recent_file_status.h" -#include <QFileInfo> - -// Sigh. The Qt 4 documentation says we should subclass QThread here. Other sources -// insist that we should subclass QObject, then move it to a newly created QThread. -//RecentFileStatus::RecentFileStatus(const QString &filename, QObject *parent) : -// QObject(parent), filename_(filename), size_(0) -//{ -//} +RecentFileStatus::RecentFileStatus(const QString filename, QObject *parent) : + QThread(parent), filename_(filename) +{ +} -void RecentFileStatus::start(void) { - QFileInfo fi; +QString RecentFileStatus::getFilename() const { + return (filename_); +} - fi.setFile(filename_); +void RecentFileStatus::run() { + fileinfo_.setFile(filename_); - if (fi.isFile() && fi.isReadable()) { - emit statusFound(filename_, fi.size(), true); + if (fileinfo_.isFile() && fileinfo_.isReadable()) { + emit statusFound(filename_, fileinfo_.size(), true); } else { emit statusFound(filename_, 0, false); } diff --git a/ui/qt/recent_file_status.h b/ui/qt/recent_file_status.h index b3cef5c9dd..1afc73e4d8 100644 --- a/ui/qt/recent_file_status.h +++ b/ui/qt/recent_file_status.h @@ -22,29 +22,28 @@ #ifndef RECENT_FILE_STATUS_H #define RECENT_FILE_STATUS_H -#include <QObject> +#include <QThread> +#include <QFileInfo> -class RecentFileStatus : public QObject +// Sigh. The Qt 4 documentation says we should subclass QThread here. Other sources +// insist that we should subclass QObject, then move it to a newly created QThread. +class RecentFileStatus : public QThread { Q_OBJECT public: - RecentFileStatus(const QString filename, QObject *parent = 0) : - QObject(parent), filename_(filename), size_(0) {} + RecentFileStatus(const QString filename, QObject *parent = 0); - QString getFilename() const { return (filename_); } - size_t getSize() const { return (size_); } - void quit() { emit finished(); } + QString getFilename() const; + +protected: + void run(); private: - QString filename_; - size_t size_; + QString filename_; + QFileInfo fileinfo_; signals: void statusFound(const QString filename = QString(), qint64 size = 0, bool accessible = false); - void finished(); - -public slots: - void start(); }; diff --git a/ui/qt/wireshark_application.cpp b/ui/qt/wireshark_application.cpp index b3a98f4455..efe8f0e976 100644 --- a/ui/qt/wireshark_application.cpp +++ b/ui/qt/wireshark_application.cpp @@ -179,26 +179,18 @@ extern "C" void menu_recent_file_write_all(FILE *rf) { void WiresharkApplication::refreshRecentFiles(void) { recent_item_status *ri; RecentFileStatus *rf_status; - QThread *rf_thread; foreach (ri, recent_items_) { if (ri->in_thread) { continue; } - rf_thread = new QThread; rf_status = new RecentFileStatus(ri->filename); - rf_status->moveToThread(rf_thread); - - connect(rf_thread, SIGNAL(started()), rf_status, SLOT(start())); - connect(rf_status, SIGNAL(statusFound(QString, qint64, bool)), this, SLOT(itemStatusFinished(QString, qint64, bool)), Qt::QueuedConnection); - connect(rf_status, SIGNAL(finished()), rf_thread, SLOT(quit())); connect(rf_status, SIGNAL(finished()), rf_status, SLOT(deleteLater())); - - rf_thread->start(); + rf_status->start(); } } @@ -465,7 +457,6 @@ void WiresharkApplication::cleanup() void WiresharkApplication::itemStatusFinished(const QString filename, qint64 size, bool accessible) { recent_item_status *ri; - RecentFileStatus *rf_status = qobject_cast<RecentFileStatus *>(QObject::sender()); foreach (ri, recent_items_) { if (filename == ri->filename && (size != ri->size || accessible != ri->accessible)) { @@ -476,10 +467,6 @@ void WiresharkApplication::itemStatusFinished(const QString filename, qint64 siz emit updateRecentItemStatus(filename, size, accessible); } } - - if (rf_status) { - rf_status->quit(); - } } WiresharkApplication::WiresharkApplication(int &argc, char **argv) : |