From 29423dcc76970253fd5bca43d0abba4876b85b85 Mon Sep 17 00:00:00 2001 From: Olivier Goffart Date: Wed, 20 Jan 2010 14:12:49 +0100 Subject: Fix crashes in QByteArray tst_QByteArray is was crashing on linux 64bit. The memory was freed twice, once by qRealloc, and one by QScopePointer::reset This patch will leak if qRealloc fails because of OutOfMemory. But we do not care as it is a corner case. Reviewed-by: Harald Fernengel Reviewed-by: Robert Griebl --- src/corelib/tools/qbytearray.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/corelib/tools/qbytearray.cpp b/src/corelib/tools/qbytearray.cpp index d2fbf5a..4049925 100644 --- a/src/corelib/tools/qbytearray.cpp +++ b/src/corelib/tools/qbytearray.cpp @@ -538,7 +538,7 @@ QByteArray qUncompress(const uchar* data, int nbytes) forever { ulong alloc = len; - d.reset(q_check_ptr(static_cast(qRealloc(d.data(), sizeof(QByteArray::Data) + alloc)))); + d.reset(q_check_ptr(static_cast(qRealloc(d.take(), sizeof(QByteArray::Data) + alloc)))); if (!d) { // we are not allowed to crash here when compiling with QT_NO_EXCEPTIONS qWarning("qUncompress: could not allocate enough memory to uncompress data"); @@ -551,7 +551,7 @@ QByteArray qUncompress(const uchar* data, int nbytes) switch (res) { case Z_OK: if (len != alloc) { - d.reset(q_check_ptr(static_cast(qRealloc(d.data(), sizeof(QByteArray::Data) + len)))); + d.reset(q_check_ptr(static_cast(qRealloc(d.take(), sizeof(QByteArray::Data) + len)))); if (!d) { // we are not allowed to crash here when compiling with QT_NO_EXCEPTIONS qWarning("qUncompress: could not allocate enough memory to uncompress data"); -- cgit v0.12