Page MenuHomePhorge

Fix memory bugs
AbandonedPublic

Authored by sicherha on May 24 2021, 2:53 PM.
Tags
None
Referenced Files
Unknown Object (File)
Fri, Mar 29, 11:25 AM
Unknown Object (File)
Mar 11 2024, 10:50 AM
Unknown Object (File)
Mar 10 2024, 9:50 PM
Unknown Object (File)
Mar 10 2024, 9:43 PM
Unknown Object (File)
Mar 10 2024, 9:38 PM
Unknown Object (File)
Feb 12 2024, 5:34 PM
Unknown Object (File)
Feb 12 2024, 3:35 PM
Unknown Object (File)
Feb 6 2024, 9:45 PM
Subscribers

Details

Reviewers
mollekopf
Summary

This revision comprises three patches that fix a use-after-free bug, potential access to dangling pointers, and a bunch of memory leaks in the tests.

Fix use-after-free bug

QByteArray::fromRawData() does not copy the contents of the source
buffer. If the resulting QByteArray object lives longer than the source
buffer, we run into use-after-free problems.

In this particular instance, the source data resides in a temporary
rvalue object.

Fix dangling pointers

std::vector gives zero guarantees that pointers to its elements remain
valid when the vector's size changes. In particular, pushing new
elements into the vector may trigger reallocation of the underlying heap
area.

Consequently, Event::delegate() needs to ensure that any modifications
to the d->attendees vector are performed before pointers to its elements
are taken and collected.

Found with Valgrind.

Fix memory leaks in tests

QTest::toString() returns a pointer to a dynamically allocated character
array. According to the Qt documentation, '[t]he caller has ownership of
the returned pointer and must ensure it is later passed to operator
delete[]'.

Diff Detail

Repository
rLK libkolab
Branch
fix-memory-bugs (branched from master)
Lint
No Lint Coverage
Unit
No Test Coverage
Build Status
Buildable 34234
Build 13657: arc lint + arc unit

Event Timeline

sicherha created this revision.
sicherha retitled this revision from Fix use-after-free bug to Fix memory bugs.May 24 2021, 2:58 PM
sicherha edited the summary of this revision. (Show Details)

Superseded by D2548. Turns out the first commit is no longer needed (and I messed up the diff during rebase).