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 <matthias.rauter@qt.io>
(cherry picked from commit dda6bf7124)
Reviewed-by: Qt Cherry-pick Bot <cherrypick_bot@qt-project.org>
(cherry picked from commit 2441be844e)
This commit is contained in:
Øystein Heskestad 2025-07-04 10:13:27 +02:00 committed by Qt Cherry-pick Bot
parent aa50d681c7
commit 47a047e5d5
1 changed files with 2 additions and 2 deletions

View File

@ -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<QIODevice, QScopedPointerDeleteLater> input(data);
QHttp2Stream *stream = getStream(streamId);
if (!stream)
return;
std::unique_ptr<QIODevice, QScopedPointerDeleteLater> input(data);
if (!input->isOpen()) {
if (!input->open(QIODevice::ReadOnly)) {
// TODO Add developer error handling