summaryrefslogtreecommitdiffstats
path: root/src/testlib/doc/snippets/code
diff options
context:
space:
mode:
authorMarc Mutz <marc.mutz@qt.io>2023-07-14 14:22:29 +0200
committerMarc Mutz <marc.mutz@qt.io>2023-07-15 16:02:04 +0000
commitecab68989e623737f7f930d7b123471ccffbfb95 (patch)
treee0ad4a56cbcc31487d55b975112a98135faa0d23 /src/testlib/doc/snippets/code
parent8cb542c2d430ffc5a6d63c404c7e700132e6364a (diff)
QCborValue: fix memleak on Array to Map coercion
When converting from an array to a map, we double the number of elements, spread the old elements out to make one free slot of space in front of each, and then place Integer values counting from 0 into the free slots. The old code contained a loop that would add a strong reference to the original elements that happen to be containers and thus are ref-counted in the first place. But this additional strong reference is not needed: In both cases, detached or in-place, the detach() call that ensured unique ownership of 'map/dst' will have either directly or indirectly updated the ref-counts of the elements correctly, and the following loops just reshuffle the elements in the QList, they don't create new copies (QtCbor::Elements doesn't by itself manipulate container->ref, but even if it did, the copy would have increased, and the assignment of the Integers would have decreased, the ref-count again). Adding the strong ref without a user then caused the container members to be leaked. Fix by removing the loop. [ChangeLog][QtCore][QCborValue] Fixed a memory leak when an array was coerced into a map. Amends ccea34464075759424e61806c7bc98ee3e658670. Not picking to 6.4 as it's closed at this time. Fixes: QTBUG-115249 Pick-to: 6.6 6.5 Change-Id: I369c372e91c3f0cfe3c65f9b0ea8507d08fdaf48 Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
Diffstat (limited to 'src/testlib/doc/snippets/code')
0 files changed, 0 insertions, 0 deletions