arp: fixes to implementation (#18)

* typo in error text
* compactQueries was keeping invalid queries
* compactQueries accidentally ended up creating shared slices
This commit is contained in:
Egon Elbre
2026-01-12 22:27:26 +02:00
committed by GitHub
parent 1a427323f2
commit be2d380753
3 changed files with 89 additions and 3 deletions
+8 -2
View File
@@ -129,8 +129,14 @@ func (h *Handler) DiscardQuery(protoAddr []byte) error {
func (h *Handler) compactQueries() {
validOff := 0
for i := 0; i < len(h.queries); i++ {
if h.queries[i].isInvalid() {
h.queries[validOff] = h.queries[i]
if !h.queries[i].isInvalid() {
if i != validOff {
// We swap the queries here so that when `StartQuery` extends
// queries slice, we don't have sharing of the internal structures.
// An alternative would be to zero things, however that would incur
// an allocation cost.
h.queries[validOff], h.queries[i] = h.queries[i], h.queries[validOff]
}
validOff++
}
}