From d14c6aa5855ebfb8bb624efd7817bb3cdd4c96e4 Mon Sep 17 00:00:00 2001 From: Arno Rehn Date: Mon, 4 Feb 2019 11:51:52 +0100 Subject: 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 --- src/webchannel/qmetaobjectpublisher.cpp | 8 ++++++-- tests/auto/webchannel/tst_webchannel.cpp | 16 ++++++++++++++++ tests/auto/webchannel/tst_webchannel.h | 1 + 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(); -- cgit v1.2.3