File: 1002_Avoid-crash-while-parsing-vcards-from-different-threads.patch

package info (click to toggle)
qtpim-opensource-src 5.0~git20201102.f9a8f0fc%2Bdfsg1-7
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 18,236 kB
  • sloc: cpp: 82,965; xml: 91; makefile: 81; javascript: 67
file content (34 lines) | stat: -rw-r--r-- 1,233 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
Author: Ubuntu Touch Developers
Description: Avoid crash while parsing vCards from different threads.
Forwarded: https://lists.qt-project.org/pipermail/development/2020-March/039208.html

=== modified file 'src/versit/qversitreader_p.cpp'
--- a/src/versit/qversitreader_p.cpp
+++ b/src/versit/qversitreader_p.cpp
@@ -43,6 +43,7 @@
 #include <QtCore/qbuffer.h>
 #include <QtCore/qtextcodec.h>
 #include <QtCore/qvariant.h>
+#include <QtCore/QReadWriteLock>
 
 #include "qversitutils_p.h"
 
@@ -428,7 +429,18 @@
 
 QHash<QPair<QVersitDocument::VersitType,QString>, QVersitProperty::ValueType>*
 QVersitReaderPrivate::valueTypeMap() {
+    static QReadWriteLock valueTypeMapLock;
+
+    QReadLocker readLock(&valueTypeMapLock);
     if (mValueTypeMap == 0) {
+        readLock.unlock();
+
+        QWriteLocker writeLock(&valueTypeMapLock);
+        // check if map still empty
+        if (mValueTypeMap) {
+            return mValueTypeMap;
+        }
+
         mValueTypeMap = new QHash<QPair<QVersitDocument::VersitType,QString>, QVersitProperty::ValueType>();
         mValueTypeMap->insert(qMakePair(QVersitDocument::VCard21Type, QString::fromLatin1("AGENT")),
                              QVersitProperty::VersitDocumentType);