summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMate Barany <mate.barany@qt.io>2024-06-25 15:12:51 +0200
committerMate Barany <mate.barany@qt.io>2024-06-27 02:08:19 +0200
commita99b9aedf16145d9d11cc78fd97c7159c7989226 (patch)
treeffdd7bbb681c4935a673f98f02528a8003838bb9
parentaea27282b783059ef52e928e811029cedb98ebf9 (diff)
Remove ProtocolHandlerDeleter
It has only a one time use and there is a nicer way to do that. Found by an Axivion scan. Task-number: QTBUG-125026 Change-Id: I9de8263fe1ea55608a8129f990b490e2f86e9479 Reviewed-by: MÃ¥rten Nordheim <marten.nordheim@qt.io>
-rw-r--r--src/network/access/qhttpnetworkconnectionchannel.cpp32
1 files changed, 6 insertions, 26 deletions
diff --git a/src/network/access/qhttpnetworkconnectionchannel.cpp b/src/network/access/qhttpnetworkconnectionchannel.cpp
index 8688e4b8d71..336256f7714 100644
--- a/src/network/access/qhttpnetworkconnectionchannel.cpp
+++ b/src/network/access/qhttpnetworkconnectionchannel.cpp
@@ -27,20 +27,6 @@
QT_BEGIN_NAMESPACE
-namespace
-{
-
-class ProtocolHandlerDeleter : public QObject
-{
-public:
- explicit ProtocolHandlerDeleter(QAbstractProtocolHandler *h) : handler(h) {}
- ~ProtocolHandlerDeleter() { delete handler; }
-private:
- QAbstractProtocolHandler *handler = nullptr;
-};
-
-}
-
// TODO: Put channel specific stuff here so it does not pollute qhttpnetworkconnection.cpp
// Because in-flight when sending a request, the server might close our connection (because the persistent HTTP
@@ -475,18 +461,12 @@ void QHttpNetworkConnectionChannel::allDone()
// As allDone() gets called from the protocol handler, it's not yet
// safe to delete it. There is no 'deleteLater', since
- // QAbstractProtocolHandler is not a QObject. Instead we do this
- // trick with ProtocolHandlerDeleter, a QObject-derived class.
- // These dances below just make it somewhat exception-safe.
- // 1. Create a new owner:
- QAbstractProtocolHandler *oldHandler = protocolHandler.get();
- auto deleter = std::make_unique<ProtocolHandlerDeleter>(oldHandler);
- // 2. Retire the old one:
- Q_UNUSED(protocolHandler.release());
- // 3. Call 'deleteLater':
- deleter->deleteLater();
- // 3. Give up the ownerthip:
- Q_UNUSED(deleter.release());
+ // QAbstractProtocolHandler is not a QObject. Instead delete it in
+ // a queued emission.
+
+ QMetaObject::invokeMethod(this, [oldHandler = std::move(protocolHandler)]() mutable {
+ oldHandler.reset();
+ }, Qt::QueuedConnection);
connection->fillHttp2Queue();
protocolHandler.reset(new QHttp2ProtocolHandler(this));