Bug 403201 - Detect passing the wrong parent for members
Summary: Detect passing the wrong parent for members
Status: REPORTED
Alias: None
Product: clazy
Classification: Developer tools
Component: general (show other bugs)
Version: unspecified
Platform: Other Linux
: NOR wishlist
Target Milestone: ---
Assignee: Sergio Martins
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2019-01-14 08:20 UTC by kpopv
Modified: 2019-04-25 16:07 UTC (History)
1 user (show)

See Also:
Latest Commit:
Version Fixed In:
Sentry Crash Report:


Attachments
Minimal example (3.19 KB, application/zip)
2019-01-14 08:20 UTC, kpopv
Details

Note You need to log in before you can comment on or make changes to this bug.
Description kpopv 2019-01-14 08:20:49 UTC
Created attachment 117455 [details]
Minimal example

SUMMARY
QObject members can be constructed with this as parent so that they get cleaned up as part of the memory management of QObject trees. On construction of a QObject derived class, the passed in parent should be passed on to the superclass while this should be used as parent of all QObject derived members. 

It is not uncommon to see parent passed incorrectly to members, it would be nice if clazy could detect this.

STEPS TO REPRODUCE
1. Open the attached project and run it. It is expected to crash.

OBSERVED RESULT
1. m_c is destructed before m_b because m_c's parent is set incorrectly to a instead of b (during construction of b). This causes ~B to call a method on an already destroyed m_c, thus crashing the application.

EXPECTED RESULT
1. m_c(new C(this)) instead of m_c(new C(parent))

SOFTWARE/OS VERSIONS
Windows: 7
Qt Version: 5.9
Comment 1 Sergio Martins 2019-04-25 16:07:32 UTC
Could make sense.

If there's too many false-positives we can always disable it by default