As described in the associated comment, we need to reallocate usedVars
and usedPkgNames in initFiles, as they are nilled out at the end of
Checker.Files, which may be called multiple times.
For #72122
For #72826
Change-Id: I9f6eb86e072d9d43a8720f6a5e86d827de6006a9
Reviewed-on: https://go-review.googlesource.com/c/go/+/655437
Auto-Submit: Robert Findley <rfindley@google.com>
Reviewed-by: Robert Griesemer <gri@google.com>
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Reviewed-by: Alan Donovan <adonovan@google.com>
(cherry picked from commit
fe9b292b11355af6b5f6e1d9247b88fa134657ed)
Reviewed-on: https://go-review.googlesource.com/c/go/+/657695
Auto-Submit: Dmitri Shuralyov <dmitshur@google.com>
TryBot-Bypass: Dmitri Shuralyov <dmitshur@google.com>
check.objPath = nil
check.cleaners = nil
+ // We must initialize usedVars and usedPkgNames both here and in NewChecker,
+ // because initFiles is not called in the CheckExpr or Eval codepaths, yet we
+ // want to free this memory at the end of Files ('used' predicates are
+ // only needed in the context of a given file).
+ check.usedVars = make(map[*Var]bool)
+ check.usedPkgNames = make(map[*PkgName]bool)
+
// determine package name and collect valid files
pkg := check.pkg
for _, file := range files {
check.objPath = nil
check.cleaners = nil
+ // We must initialize usedVars and usedPkgNames both here and in NewChecker,
+ // because initFiles is not called in the CheckExpr or Eval codepaths, yet we
+ // want to free this memory at the end of Files ('used' predicates are
+ // only needed in the context of a given file).
+ check.usedVars = make(map[*Var]bool)
+ check.usedPkgNames = make(map[*PkgName]bool)
+
// determine package name and collect valid files
pkg := check.pkg
for _, file := range files {