diff options
author | Gerald Combs <gerald@wireshark.org> | 2018-02-02 09:37:50 -0800 |
---|---|---|
committer | Michael Mann <mmann78@netscape.net> | 2018-02-03 02:06:49 +0000 |
commit | a4bb6c2d395ac1e30e116bc2780fa143df2dc1ab (patch) | |
tree | 923c124c701506c8e3508b73abdf13ae9579ff4a /ui/qt | |
parent | e3a76761861cf3baad8e9c998345be59bc725a2b (diff) |
Make a deep copy of our filename in RecentFileStatus.
QStrings are implictly shared as described at
http://doc.qt.io/qt-5/implicit-sharing.html. This is normally useful,
but RecentFileStatus is passed a QString before it does its work in a
separate thread.
Make a deep copy of the filename in order to ensure local ownership and
to avoid having to fool around with a QMutex (which might not be
recognized by ThreadSanitizer[1] or Helgrind[2]).
Remove getFilename since it was unused.
[1] https://github.com/google/sanitizers/issues/460
[2] http://valgrind.org/docs/manual/hg-manual.html
Change-Id: I5b5c329505ed8c02d30043a2a6d1ded625924b9f
Reviewed-on: https://code.wireshark.org/review/25572
Reviewed-by: Gerald Combs <gerald@wireshark.org>
Petri-Dish: Gerald Combs <gerald@wireshark.org>
Tested-by: Petri Dish Buildbot
Reviewed-by: Michael Mann <mmann78@netscape.net>
Diffstat (limited to 'ui/qt')
-rw-r--r-- | ui/qt/recent_file_status.cpp | 9 | ||||
-rw-r--r-- | ui/qt/recent_file_status.h | 4 |
2 files changed, 5 insertions, 8 deletions
diff --git a/ui/qt/recent_file_status.cpp b/ui/qt/recent_file_status.cpp index 10e2ef7129..50ce6591ab 100644 --- a/ui/qt/recent_file_status.cpp +++ b/ui/qt/recent_file_status.cpp @@ -10,7 +10,9 @@ #include "recent_file_status.h" RecentFileStatus::RecentFileStatus(const QString filename, QObject *parent) : - QObject(parent), filename_(filename) + QObject(parent), + // Force a deep copy. + filename_(QString::fromUtf16(filename.utf16())) { // We're a QObject, which means that we emit a destroyed signal, // which might happen at the wrong time when automatic deletion is @@ -18,14 +20,11 @@ RecentFileStatus::RecentFileStatus(const QString filename, QObject *parent) : setAutoDelete(false); // Qt::BlockingQueuedConnection shouldn't be necessary but it doesn't // hurt either. + // We could alternatively pass a qHash of the filename. connect(this, SIGNAL(statusFound(QString, qint64, bool)), parent, SLOT(itemStatusFinished(QString, qint64, bool)), Qt::BlockingQueuedConnection); } -QString RecentFileStatus::getFilename() const { - return (filename_); -} - void RecentFileStatus::run() { fileinfo_.setFile(filename_); diff --git a/ui/qt/recent_file_status.h b/ui/qt/recent_file_status.h index 3887303b94..c012d35195 100644 --- a/ui/qt/recent_file_status.h +++ b/ui/qt/recent_file_status.h @@ -19,13 +19,11 @@ class RecentFileStatus : public QObject, public QRunnable public: RecentFileStatus(const QString filename, QObject *parent); - QString getFilename() const; - protected: void run(); private: - QString filename_; + const QString filename_; QFileInfo fileinfo_; signals: |