Skip to content

Commit

Permalink
Fix memory leaks in rules which kept references to trees of previous …
Browse files Browse the repository at this point in the history
…files (#721)
  • Loading branch information
pynicolas authored Nov 16, 2020
1 parent a65a7d3 commit 8a16d68
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
import org.sonar.php.cfg.LiveVariablesAnalysis;
import org.sonar.plugins.php.api.cfg.ControlFlowGraph;
import org.sonar.plugins.php.api.symbols.Symbol;
import org.sonar.plugins.php.api.tree.CompilationUnitTree;
import org.sonar.plugins.php.api.tree.Tree;
import org.sonar.plugins.php.api.tree.declaration.FunctionDeclarationTree;
import org.sonar.plugins.php.api.tree.declaration.FunctionTree;
Expand All @@ -43,6 +44,12 @@ public class ReassignedBeforeUsedCheck extends PHPVisitorCheck {

private final Set<Symbol> investigatedParameters = new HashSet<>();

@Override
public void visitCompilationUnit(CompilationUnitTree tree) {
investigatedParameters.clear();
super.visitCompilationUnit(tree);
}

@Override
public void visitFunctionDeclaration(FunctionDeclarationTree tree) {
visitFunctionTree(tree);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
import org.sonar.php.tree.TreeUtils;
import org.sonar.plugins.php.api.symbols.Symbol;
import org.sonar.plugins.php.api.symbols.SymbolTable;
import org.sonar.plugins.php.api.tree.CompilationUnitTree;
import org.sonar.plugins.php.api.tree.Tree;
import org.sonar.plugins.php.api.tree.declaration.MethodDeclarationTree;
import org.sonar.plugins.php.api.tree.expression.ExpressionTree;
Expand All @@ -52,6 +53,12 @@ public class NoAssertionInTestCheck extends PhpUnitCheck {

private final Map<MethodDeclarationTree, Boolean> assertionInMethod = new HashMap<>();

@Override
public void visitCompilationUnit(CompilationUnitTree tree) {
assertionInMethod.clear();
super.visitCompilationUnit(tree);
}

@Override
public void visitMethodDeclaration(MethodDeclarationTree tree) {
if (!isTestCaseMethod(tree)) {
Expand Down

0 comments on commit 8a16d68

Please sign in to comment.