From 47a047e5d543f9ae025437c4b9ef32bdc5d65b5f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=98ystein=20Heskestad?= Date: Fri, 4 Jul 2025 10:13:27 +0200 Subject: [PATCH] Fix HTTP/2 handling leaking device if stream is not found or inactive Move unique_ptr taking ownership of QIODevice earlier in the HTTP/2 handling to prevent it from leaking if the stream is not found or is inactive (closed or idle). The write function for devices must always take owvnership the device and destroy it when it is no longer needed. Task-number: QTBUG-137330 Pick-to: 6.8 Change-Id: I5c7df2dfaca25c382717ec9afe6607f1919475d7 Reviewed-by: Matthias Rauter (cherry picked from commit dda6bf71245cd075039a9a2714b1940db29a6781) Reviewed-by: Qt Cherry-pick Bot (cherry picked from commit 2441be844ec15a5e37d9eef3637929d96ee1ab9f) --- src/httpserver/qhttpserverhttp2protocolhandler.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/httpserver/qhttpserverhttp2protocolhandler.cpp b/src/httpserver/qhttpserverhttp2protocolhandler.cpp index 4e6909b..12f0c68a 100644 --- a/src/httpserver/qhttpserverhttp2protocolhandler.cpp +++ b/src/httpserver/qhttpserverhttp2protocolhandler.cpp @@ -124,12 +124,12 @@ void QHttpServerHttp2ProtocolHandler::write(QHttpServerResponder::StatusCode sta void QHttpServerHttp2ProtocolHandler::write(QIODevice *data, const QHttpHeaders &headers, QHttpServerResponder::StatusCode status, quint32 streamId) { + std::unique_ptr input(data); + QHttp2Stream *stream = getStream(streamId); if (!stream) return; - std::unique_ptr input(data); - if (!input->isOpen()) { if (!input->open(QIODevice::ReadOnly)) { // TODO Add developer error handling