Fix memory leak of KQuickAddons::ConfigModule objects
ClosedPublic

Authored by davidedmundson on Oct 16 2019, 9:28 PM.

Details

Summary

When we create a KQuickAddons::ConfigModule in the factory we didn't
set a parent. It is passed to the wrapper KCModuleQML, and even though
the wrapper is memory manager the ConfigModule object itself was not.

This lead to another crash as the KAboutData is deleted twice, which was
fixed with an explicit copy

BUG: 412998

Test Plan

qDebug inside the colours KCM destructor
It now appears when changing tabs

Diff Detail

Repository
R295 KCMUtils
Branch
master
Lint
No Linters Available
Unit
No Unit Test Coverage
Build Status
Buildable 17789
Build 17807: arc lint + arc unit
davidedmundson created this revision.Oct 16 2019, 9:28 PM
Restricted Application added a project: Frameworks. · View Herald TranscriptOct 16 2019, 9:28 PM
Restricted Application added a subscriber: kde-frameworks-devel. · View Herald Transcript
davidedmundson requested review of this revision.Oct 16 2019, 9:28 PM

Slightly refactor so the teardown order deletes the QML content and then
deletes the parent window which is a bit more logical.

Now kscreen KCM doesn't crash even with the extra prompts

ervin requested changes to this revision.Oct 17 2019, 6:52 AM
ervin added a subscriber: ervin.
ervin added inline comments.
src/kcmoduleloader.cpp
101 ↗(On Diff #68096)

Easier fix is likely to wrap that into a std::unique_ptr here and calling release() on it when creating the KCModuleQml later on. Would be even better to change KCModuleQml to take a std::unique_ptr in the ctor and use a unique_ptr internally (AFAICT it's not public API so doable).

That's admittedly more intrusive change though but at least would make some of that ownership issues more explicit and easier to track.

107 ↗(On Diff #68096)

This is unreachable code. You want to delete before the reportError call but after the cm->errorString() call.

This revision now requires changes to proceed.Oct 17 2019, 6:52 AM
davidedmundson edited the summary of this revision. (Show Details)
davidedmundson removed a reviewer: ervin.
davidedmundson removed a subscriber: ervin.

Use unique_ptr

davidedmundson marked 2 inline comments as done.Oct 17 2019, 9:13 AM
ervin accepted this revision.Oct 17 2019, 9:42 AM

Looks good to me, I'll accept it but better wait a bit in case others want to chip in.

This revision is now accepted and ready to land.Oct 17 2019, 9:42 AM
broulik accepted this revision.Oct 17 2019, 11:59 AM
This revision was automatically updated to reflect the committed changes.