summaryrefslogtreecommitdiffstats
path: root/src/corelib/tools/qcryptographichash.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/corelib/tools/qcryptographichash.cpp')
-rw-r--r--src/corelib/tools/qcryptographichash.cpp8
1 files changed, 8 insertions, 0 deletions
diff --git a/src/corelib/tools/qcryptographichash.cpp b/src/corelib/tools/qcryptographichash.cpp
index f6db6b976c..e0db1a33eb 100644
--- a/src/corelib/tools/qcryptographichash.cpp
+++ b/src/corelib/tools/qcryptographichash.cpp
@@ -40,6 +40,8 @@
#include <qcryptographichash.h>
#include <qiodevice.h>
+#include <qmutex.h>
+#include <private/qlocking_p.h>
#include "../../3rdparty/sha1/sha1.cpp"
@@ -164,6 +166,8 @@ public:
};
void sha3Finish(int bitCount, Sha3Variant sha3Variant);
#endif
+ // protects result in result()
+ QBasicMutex finalizeMutex;
QByteArray result;
};
@@ -468,6 +472,9 @@ bool QCryptographicHash::addData(QIODevice *device)
*/
QByteArray QCryptographicHash::result() const
{
+ // result() is a const function, so concurrent calls are allowed; protect:
+ const auto lock = qt_scoped_lock(d->finalizeMutex);
+ // check that no other thread already finalized before us:
if (!d->result.isEmpty())
return d->result;
@@ -575,6 +582,7 @@ QByteArray QCryptographicHash::result() const
}
#endif
}
+
return d->result;
}