Skip to content

Find, verify, and analyze leaked credentials

Dont pre-allocate errors slice. (#1083)

ahrave47cc2451fb9
diff --git a/pkg/sources/circleci/circleci.go b/pkg/sources/circleci/circleci.go
index ad0fb63db..bdf22d4c1 100644
--- a/pkg/sources/circleci/circleci.go
+++ b/pkg/sources/circleci/circleci.go
@@ -82,7 +82,7 @@ func (s *Source) Chunks(ctx context.Context, chunksChan chan *sources.Chunk) err
}
var scanned uint64
- scanErrs := sources.NewScanErrors(len(projects))
+ scanErrs := sources.NewScanErrors()
for _, proj := range projects {
proj := proj
diff --git a/pkg/sources/errors.go b/pkg/sources/errors.go
index 2d9cc274d..0d73338d1 100644
--- a/pkg/sources/errors.go
+++ b/pkg/sources/errors.go
@@ -12,8 +12,8 @@ type ScanErrors struct {
}
// NewScanErrors creates a new thread safe error collector.
-func NewScanErrors(projects int) *ScanErrors {
- return &ScanErrors{errors: make([]error, 0, projects)}
+func NewScanErrors() *ScanErrors {
+ return &ScanErrors{errors: make([]error, 0)}
}
// Add an error to the collection in a thread-safe manner.
diff --git a/pkg/sources/errors_test.go b/pkg/sources/errors_test.go
index a76c37dab..30334cdc9 100644
--- a/pkg/sources/errors_test.go
+++ b/pkg/sources/errors_test.go
@@ -37,7 +37,7 @@ func TestNewScanErrors(t *testing.T) {
for _, tc := range testCases {
t.Run(tc.name, func(t *testing.T) {
- got := NewScanErrors(tc.projects)
+ got := NewScanErrors()
if !reflect.DeepEqual(got, tc.want) {
t.Errorf("got %+v, want %+v", got, tc.want)
@@ -76,7 +76,7 @@ func TestScanErrorsAdd(t *testing.T) {
for _, tc := range testCases {
t.Run(tc.name, func(t *testing.T) {
- se := NewScanErrors(tc.wantErr)
+ se := NewScanErrors()
var wg sync.WaitGroup
for i := 0; i < tc.concurrency; i++ {
@@ -127,7 +127,7 @@ func TestScanErrorsCount(t *testing.T) {
for _, tc := range testCases {
t.Run(tc.name, func(t *testing.T) {
- se := NewScanErrors(tc.wantErrCnt)
+ se := NewScanErrors()
var wg sync.WaitGroup
for i := 0; i < tc.concurrency; i++ {
diff --git a/pkg/sources/gitlab/gitlab.go b/pkg/sources/gitlab/gitlab.go
index 5cd313a03..73a1283c0 100644
--- a/pkg/sources/gitlab/gitlab.go
+++ b/pkg/sources/gitlab/gitlab.go
@@ -338,7 +338,7 @@ func (s *Source) scanRepos(ctx context.Context, chunksChan chan *sources.Chunk)
// If there is resume information available, limit this scan to only the repos that still need scanning.
reposToScan, progressIndexOffset := sources.FilterReposToResume(s.repos, s.GetProgress().EncodedResumeInfo)
s.repos = reposToScan
- scanErrs := sources.NewScanErrors(len(s.repos))
+ scanErrs := sources.NewScanErrors()
for i, repo := range s.repos {
i, repoURL := i, repo