From cb4cb61883008d5eb03d56149783dd136a76e6ca Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?M=C3=A5rten=20Nordheim?= Date: Tue, 3 Oct 2023 13:13:16 +0200 Subject: [PATCH] QHttpThreadDelegate: use new(std::nothrow) instead of try..catch We usually compile without exceptions, so the try..catch is a noop. So, if the `new` fails we would crash (or get UB) anyway. Instead of that, use the nothrow version of `new` and check the result. Pick-to: 6.5 Change-Id: I1902b717c70afcc44c1f3237370aae346262452a Reviewed-by: Marc Mutz Reviewed-by: Timur Pocheptsov (cherry picked from commit 51c812af0747573ccf07fc232d860170c4ba2877) Reviewed-by: Qt Cherry-pick Bot --- src/network/access/qhttpthreaddelegate.cpp | 13 +++++-------- 1 file changed, 5 insertions(+), 8 deletions(-) diff --git a/src/network/access/qhttpthreaddelegate.cpp b/src/network/access/qhttpthreaddelegate.cpp index 261a1eccd67..b0ae0dcf446 100644 --- a/src/network/access/qhttpthreaddelegate.cpp +++ b/src/network/access/qhttpthreaddelegate.cpp @@ -584,14 +584,11 @@ void QHttpThreadDelegate::headerChangedSlot() // Is using a zerocopy buffer allowed by user and possible with this reply? if (httpReply->supportsUserProvidedDownloadBuffer() && (downloadBufferMaximumSize > 0) && (httpReply->contentLength() <= downloadBufferMaximumSize)) { - QT_TRY { - char *buf = new char[httpReply->contentLength()]; // throws if allocation fails - if (buf) { - downloadBuffer = QSharedPointer(buf, [](auto p) { delete[] p; }); - httpReply->setUserProvidedDownloadBuffer(buf); - } - } QT_CATCH(const std::bad_alloc &) { - // in out of memory situations, don't use downloadbuffer. + char *buf = new (std::nothrow) char[httpReply->contentLength()]; + // in out of memory situations, don't use downloadBuffer. + if (buf) { + downloadBuffer = QSharedPointer(buf, [](auto p) { delete[] p; }); + httpReply->setUserProvidedDownloadBuffer(buf); } }