Fix crash due to using an attribute from a collection that went out of scope

Authored by dfaure on Mar 27 2019, 1:47 PM.



Probably a consequence of the const/non-const changes (detaching?)

Test Plan

Untested, but based on a crash report by Allen, pointing to
ETMCalendar::alarms() calling BlockAlarmsAttribute::isAlarmTypeBlocked
on line 579.

Diff Detail

R170 Akonadi Calendar
No Linters Available
No Unit Test Coverage
Build Status
Buildable 10195
Build 10213: arc lint + arc unit
dfaure created this revision.Mar 27 2019, 1:47 PM
Restricted Application added a project: KDE PIM. · View Herald TranscriptMar 27 2019, 1:47 PM
dfaure requested review of this revision.Mar 27 2019, 1:47 PM

I applied this patch locally for testing. so far so good.

dvratil added a comment.EditedMar 28 2019, 11:38 AM

Interesting, shouldn't the attribute be owned by the Collection in d->mCollectionMap? The parentCollection should be just a shallow copy, so going out of scope should just decrease the ref counter in the shared instance, nothing more. This could point to some more fundamental problem...

Could you try to turn this into some test case in Akonadi?

Bah, now I see it - the trivial fix is to just make parentCollection a const, then the call to parentCollection.attribute<>() will use the const overload and not cause a detach (or make blockedAttr a const pointer, that should do the trick as well.

This is a fairly common pattern, I wonder how many similar bugs we may have introduced by the const/non-const attribute access... :(

dvratil accepted this revision.Mar 28 2019, 11:42 AM
This revision is now accepted and ready to land.Mar 28 2019, 11:42 AM

Well, it's a copy of that collection, and the recent const/non-const change makes us detach that copy.

The alternative fix is to make that parentCollection variable const, then it will work like before. But it still reads to me like we're pointing into something that went out of scope (although with the implicit sharing it won't be the case anymore).

Indeed, your fix is the cleanest approach 👍

dfaure closed this revision.Mar 29 2019, 11:02 AM