QNetworkAccessManager: check the buffer size before allocate
The downloadBuffer size should not be larger then the downloadBufferMaximumSize. I also added a try catch for the allocation incase we are low on memory, so that we don't crash. Task-number: QTBUG-23040 Change-Id: Ib9820bc19fc5db994ede20f123f8c167a8d43ff7 Reviewed-by: Peter Hartmann <peter.hartmann@nokia.com>
This commit is contained in:
parent
ebfdb73b75
commit
44bd7c66e2
@ -472,11 +472,15 @@ void QHttpThreadDelegate::headerChangedSlot()
|
||||
|
||||
// Is using a zerocopy buffer allowed by user and possible with this reply?
|
||||
if (httpReply->supportsUserProvidedDownloadBuffer()
|
||||
&& downloadBufferMaximumSize > 0) {
|
||||
char *buf = new char[httpReply->contentLength()]; // throws if allocation fails
|
||||
if (buf) {
|
||||
downloadBuffer = QSharedPointer<char>(buf, downloadBufferDeleter);
|
||||
httpReply->setUserProvidedDownloadBuffer(buf);
|
||||
&& (downloadBufferMaximumSize > 0) && (httpReply->contentLength() <= downloadBufferMaximumSize)) {
|
||||
QT_TRY {
|
||||
char *buf = new char[httpReply->contentLength()]; // throws if allocation fails
|
||||
if (buf) {
|
||||
downloadBuffer = QSharedPointer<char>(buf, downloadBufferDeleter);
|
||||
httpReply->setUserProvidedDownloadBuffer(buf);
|
||||
}
|
||||
} QT_CATCH(const std::bad_alloc &) {
|
||||
// in out of memory situations, don't use downloadbuffer.
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user