Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Resource Leak Checker: Add a check to avoid mapping multiple keys to a ternary expression for tempVarToTree #5137

Merged
merged 2 commits into from May 11, 2022

Conversation

Nargeshdb
Copy link
Contributor

Fixes #5136

@Nargeshdb Nargeshdb changed the title Add a check to avoid mapping multiple keys to a ternary expression in tempVarToTree Add a check to avoid mapping multiple keys to a ternary expression for tempVarToTree May 10, 2022
@@ -231,7 +231,9 @@ protected ResourceLeakAnalysis createFlowAnalysis() {
* @param tree the tree of the expression the tempvar represents
*/
/* package-private */ void addTempVar(LocalVariableNode tmpVar, Tree tree) {
tempVarToTree.put(tmpVar, tree);
if (!tempVarToTree.containsValue(tree)) {
Copy link
Contributor

Choose a reason for hiding this comment

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

I'm a little concerned about this change. If addTempVar() is being called, the caller has already created a new tmpVar for the tree. It seems problematic if tmpVar gets used elsewhere but doesn't get added to the tempVarToTree mapping. What do you think of this concern?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I don't think it makes any problem because each node has to have a unique tmpVar which is defined in MustCallAnnotatedTypeFactory. But the problem here is that in ResourceLeakTransfer in visitTernaryExpression we don't check if there exist a tmpVar for the node like this.

Copy link
Contributor

Choose a reason for hiding this comment

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

Ok, assuming the tests pass, I am ok with this change for now. I'll finish reviewing once CI passes (I think there is a formatting error)

@msridhar msridhar changed the title Add a check to avoid mapping multiple keys to a ternary expression for tempVarToTree Resource Leak Checker: Add a check to avoid mapping multiple keys to a ternary expression for tempVarToTree May 11, 2022
@msridhar msridhar merged commit e8bd4ad into typetools:master May 11, 2022
wmdietl pushed a commit to eisop/checker-framework that referenced this pull request Jun 2, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Resource Leak Checker crash with IllegalArgumentException
2 participants