Make a deep copy of our filename in RecentFileStatus.
authorGerald Combs <gerald@wireshark.org>
Fri, 2 Feb 2018 17:37:50 +0000 (09:37 -0800)
committerMichael Mann <mmann78@netscape.net>
Sat, 3 Feb 2018 02:06:49 +0000 (02:06 +0000)
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>
ui/qt/recent_file_status.cpp
ui/qt/recent_file_status.h

index 10e2ef712923f0bac39600ef3eacc4c95ac8ca36..50ce6591ab217c4d45c958b345b9e2379a9cc03e 100644 (file)
@@ -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_);
 
index 3887303b9497b074cc4c625957f9c8b2769403ae..c012d3519551af68b3d25178b7a08e1ff5dce6c7 100644 (file)
@@ -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: