mirror of
https://github.com/github/codeql.git
synced 2026-04-28 10:15:14 +02:00
Merge pull request #1149 from jbj/resource-not-released-in-destructor-Qt
C++: Fix special-casing of Qt library in resource-not-released-in-destructor
This commit is contained in:
@@ -267,7 +267,7 @@ predicate automaticallyReleased(Assignment acquire)
|
||||
{
|
||||
// sub-types of the Qt type QObject are released by their parent (if they have one)
|
||||
exists(NewExpr alloc |
|
||||
alloc.getType() = qtObject() and
|
||||
alloc.getAllocatedType() = qtObject() and
|
||||
acquire.getRValue() = alloc and
|
||||
alloc.getInitializer() = qtParentConstructor().getACallToThisFunction()
|
||||
)
|
||||
|
||||
@@ -0,0 +1,25 @@
|
||||
struct QObject {
|
||||
QObject(QObject *parent);
|
||||
void setParent(QObject *parent);
|
||||
};
|
||||
|
||||
struct DerivedFromQObject : public QObject {
|
||||
DerivedFromQObject(QObject *parent);
|
||||
};
|
||||
|
||||
class MyQtUser {
|
||||
DerivedFromQObject *noParent, *constructorParent, *laterParent;
|
||||
|
||||
MyQtUser(QObject *parent) {
|
||||
// This object sets its parent pointer to null and thus must be deleted
|
||||
// manually.
|
||||
noParent = new DerivedFromQObject(nullptr); // BAD [NOT DETECTED]
|
||||
|
||||
// This object does not need to be deleted because it will be deleted by
|
||||
// its parent object when the time is right.
|
||||
constructorParent = new DerivedFromQObject(parent); // GOOD
|
||||
|
||||
laterParent = new DerivedFromQObject(nullptr); // GOOD
|
||||
laterParent->setParent(parent);
|
||||
}
|
||||
};
|
||||
Reference in New Issue
Block a user