From efc5fa938694ca8f6ba6247bf1b79cc30d656c82 Mon Sep 17 00:00:00 2001 From: Thiago Macieira Date: Mon, 11 Jul 2022 08:20:03 -0700 Subject: [PATCH] QCborValue: free container memory in case of parsing failure Holding on to the memory we've just allocated could only make sense if we supported resuming parsing, but I haven't implemented that feature yet. Change-Id: I36b24183fbd041179f2ffffd1700cf7e3558040f Reviewed-by: Edward Welbourne (cherry picked from commit 16641f625ec0ae71b34813b8eef4dcc1aeb81fc5) Reviewed-by: Qt Cherry-pick Bot --- src/corelib/serialization/qcborvalue.cpp | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/corelib/serialization/qcborvalue.cpp b/src/corelib/serialization/qcborvalue.cpp index 96c961475c3..2570e66677b 100644 --- a/src/corelib/serialization/qcborvalue.cpp +++ b/src/corelib/serialization/qcborvalue.cpp @@ -1504,14 +1504,18 @@ static inline QCborContainerPrivate *createContainerFromCbor(QCborStreamReader & } reader.enterContainer(); - if (reader.lastError() != QCborError::NoError) + if (reader.lastError() != QCborError::NoError) { + d->elements.clear(); return d; + } while (reader.hasNext() && reader.lastError() == QCborError::NoError) d->decodeValueFromCbor(reader, remainingRecursionDepth - 1); if (reader.lastError() == QCborError::NoError) reader.leaveContainer(); + else + d->elements.squeeze(); return d; }