summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorArno Rehn <a.rehn@menlosystems.com>2019-02-04 11:51:52 +0100
committerArno Rehn <a.rehn@menlosystems.com>2019-02-04 15:24:32 +0000
commitd14c6aa5855ebfb8bb624efd7817bb3cdd4c96e4 (patch)
tree2984d8ce4625d1f66b3fbaf54086cc56f2d4128e
parent38b5128c63ba38303f0587e03536ed546c1f2eca (diff)
downloadqtwebchannel-d14c6aa5855ebfb8bb624efd7817bb3cdd4c96e4.tar.gz
Also add already wrapped objects to the transport-to-objects map
Fixes a crash: Previously, when a connection was closed, the transport was not removed from the list of transports of a wrapped objects. This was because the transport was not added to the transport-to-object map in the first place. When a property update was pushed, the now dangling pointer to the "old" transport caused a crash. Change-Id: Ib980f0b874851f8f85f7a3d76d51a2c884504b96 Reviewed-by: Frederik Gladhorn <frederik.gladhorn@qt.io>
-rw-r--r--src/webchannel/qmetaobjectpublisher.cpp8
-rw-r--r--tests/auto/webchannel/tst_webchannel.cpp16
-rw-r--r--tests/auto/webchannel/tst_webchannel.h1
3 files changed, 23 insertions, 2 deletions
diff --git a/src/webchannel/qmetaobjectpublisher.cpp b/src/webchannel/qmetaobjectpublisher.cpp
index b34b39e..3b2c016 100644
--- a/src/webchannel/qmetaobjectpublisher.cpp
+++ b/src/webchannel/qmetaobjectpublisher.cpp
@@ -591,8 +591,12 @@ QJsonValue QMetaObjectPublisher::wrapResult(const QVariant &result, QWebChannelA
} else if (wrappedObjects.contains(id)) {
Q_ASSERT(object == wrappedObjects.value(id).object);
// check if this transport is already assigned to the object
- if (transport && !wrappedObjects.value(id).transports.contains(transport))
- wrappedObjects[id].transports.append(transport);
+ if (transport) {
+ if (!wrappedObjects.value(id).transports.contains(transport))
+ wrappedObjects[id].transports.append(transport);
+ if (!transportedWrappedObjects.contains(transport, id))
+ transportedWrappedObjects.insertMulti(transport, id);
+ }
classInfo = wrappedObjects.value(id).classinfo;
}
diff --git a/tests/auto/webchannel/tst_webchannel.cpp b/tests/auto/webchannel/tst_webchannel.cpp
index e46d097..57aab53 100644
--- a/tests/auto/webchannel/tst_webchannel.cpp
+++ b/tests/auto/webchannel/tst_webchannel.cpp
@@ -799,6 +799,22 @@ void TestWebChannel::testWrapValues()
}
}
+void TestWebChannel::testWrapObjectWithMultipleTransports()
+{
+ QWebChannel channel;
+ QMetaObjectPublisher *pub = channel.d_func()->publisher;
+
+ DummyTransport *dummyTransport = new DummyTransport(this);
+ DummyTransport *dummyTransport2 = new DummyTransport(this);
+
+ TestObject obj;
+
+ pub->wrapResult(QVariant::fromValue(&obj), dummyTransport);
+ pub->wrapResult(QVariant::fromValue(&obj), dummyTransport2);
+
+ QCOMPARE(pub->transportedWrappedObjects.count(), 2);
+}
+
void TestWebChannel::testJsonToVariant()
{
QWebChannel channel;
diff --git a/tests/auto/webchannel/tst_webchannel.h b/tests/auto/webchannel/tst_webchannel.h
index 40e6fba..3d725f4 100644
--- a/tests/auto/webchannel/tst_webchannel.h
+++ b/tests/auto/webchannel/tst_webchannel.h
@@ -315,6 +315,7 @@ private slots:
void testRemoveUnusedTransports();
void testPassWrappedObjectBack();
void testWrapValues();
+ void testWrapObjectWithMultipleTransports();
void testJsonToVariant();
void testInfiniteRecursion();
void testAsyncObject();