aquasecurity / tracee

Linux Runtime Security and Forensics using eBPF
https://aquasecurity.github.io/tracee/latest
Apache License 2.0
3.35k stars 394 forks source link

miss makezero in slice init #4081

Open alingse opened 1 month ago

alingse commented 1 month ago

I was running github actions to run linter makezero for top github golang repos.

see issues https://github.com/alingse/go-linter-runner/issues/1

and the github actions output https://github.com/alingse/go-linter-runner/actions/runs/9242979001/job/25426506045

====================================================================================================
append to slice `res` with non-zero initialized length at https://github.com/aquasecurity/tracee/blob/main/pkg/bufferdecoder/eventsreader.go#L384:[9](https://github.com/alingse/go-linter-runner/actions/runs/9242979001/job/25426506045#step:4:10)
====================================================================================================

the res := make([]byte, max) should be res := make([]byte, 0, max)

the origin way is no help to optimize memory allocation, the append still cause an extra allocation

geyslan commented 1 month ago

@alingse thanks for your report. @yanivagman FYI.