Skip to content

CPP: Fix function pointer/lambda related false positives in 'Resource not released in destructor'#672

Merged
jbj merged 7 commits into
github:masterfrom
geoffw0:lgtm1605
Jan 21, 2019
Merged

CPP: Fix function pointer/lambda related false positives in 'Resource not released in destructor'#672
jbj merged 7 commits into
github:masterfrom
geoffw0:lgtm1605

Conversation

@geoffw0

@geoffw0 geoffw0 commented Dec 12, 2018

Copy link
Copy Markdown
Contributor

Add some tests and fix several types of false positives in this query related to function pointers and lambdas. I've also renamed some things in the query as the terminology used had become inconsistent.

@geoffw0 geoffw0 added the C++ label Dec 12, 2018
@geoffw0 geoffw0 requested a review from a team as a code owner December 12, 2018 11:11
@geoffw0

geoffw0 commented Dec 12, 2018

Copy link
Copy Markdown
Contributor Author

This is going to conflict with #580, when that PR reaches master. I'm happy to fix that when it comes up.

@jbj jbj left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This appears to be a strict improvement. LGTM except for one comment.

releaseExpr = r.getAReleaseExpr(kind) and
releaseExpr.getEnclosingFunction().getEnclosingAccessHolder*() = acquire.getEnclosingFunction()
// here, `getEnclosingAccessHolder*` allows us to go from a nested function or lambda
// expression to the class method enclosing it.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It seems a bit coincidental that getEnclosingAccessHolder does what you want here. I'm not even sure that predicate should be public. Would getEnclosingElement not work?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes getEnclosingElement works - but we pay a substantial performance cost (~20%), according to my tests.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't see why that would be more expensive. As getEnclosingElement is cached, it's essentially free to use in a query that's part of a suite.

The join you have there is of course risky since it's of the form restrictedExpr1.getEnclosingSomething() = restrictedExpr2.getEnclosingSomething(), and there's never a good way to join-order that. The slightest change can affect whether you get the magic and join order you need.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You're persuading me... I'll try testing again in the context of a warmed-up cache.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@jbj

jbj commented Jan 14, 2019

Copy link
Copy Markdown
Contributor

@geoffw0 let's try to get this in before the next dist upgrade

@jbj jbj left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'll merge this to make sure it gets into today's dist upgrade.

@jbj jbj merged commit 9561fda into github:master Jan 21, 2019
cklin pushed a commit that referenced this pull request May 23, 2022
Post-release preparation for codeql-cli-2.7.6
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants