File tree Expand file tree Collapse file tree 2 files changed +26
-1
lines changed
test/query-tests/jsf/4.10 Classes/AV Rule 79 Expand file tree Collapse file tree 2 files changed +26
-1
lines changed Original file line number Diff line number Diff line change @@ -267,7 +267,7 @@ predicate automaticallyReleased(Assignment acquire)
267267{
268268 // sub-types of the Qt type QObject are released by their parent (if they have one)
269269 exists ( NewExpr alloc |
270- alloc .getType ( ) = qtObject ( ) and
270+ alloc .getAllocatedType ( ) = qtObject ( ) and
271271 acquire .getRValue ( ) = alloc and
272272 alloc .getInitializer ( ) = qtParentConstructor ( ) .getACallToThisFunction ( )
273273 )
Original file line number Diff line number Diff line change 1+ struct QObject {
2+ QObject (QObject *parent);
3+ void setParent (QObject *parent);
4+ };
5+
6+ struct DerivedFromQObject : public QObject {
7+ DerivedFromQObject (QObject *parent);
8+ };
9+
10+ class MyQtUser {
11+ DerivedFromQObject *noParent, *constructorParent, *laterParent;
12+
13+ MyQtUser (QObject *parent) {
14+ // This object sets its parent pointer to null and thus must be deleted
15+ // manually.
16+ noParent = new DerivedFromQObject (nullptr ); // BAD [NOT DETECTED]
17+
18+ // This object does not need to be deleted because it will be deleted by
19+ // its parent object when the time is right.
20+ constructorParent = new DerivedFromQObject (parent); // GOOD
21+
22+ laterParent = new DerivedFromQObject (nullptr ); // GOOD
23+ laterParent->setParent (parent);
24+ }
25+ };
You can’t perform that action at this time.
0 commit comments