miekg / dns

DNS library in Go
https://miek.nl/2014/august/16/go-dns-package
BSD 3-Clause "New" or "Revised" License
7.86k stars 1.12k forks source link

Use of []byte in sync.Pool #1578

Open johanbrandhorst opened 1 week ago

johanbrandhorst commented 1 week ago

Hi!

staticcheck flags the use of sync.Pool in server.go as incorrect, as it's passing []byte instead of *[]byte, which means every instance ends up allocating a slice header. See https://staticcheck.dev/docs/checks/#SA6002 and https://go-review.googlesource.com/c/go/+/24371 for more information, discussion and examples.

To fix it, I suggest changing instances of Put to pass a reference to the slice, and to ensure that the same alloc that was got is put back.