Skip to content

Commit

Permalink
Properly use sync pools (pointers)
Browse files Browse the repository at this point in the history
  • Loading branch information
lixmal committed Dec 22, 2024
1 parent 802a9be commit 84df403
Showing 1 changed file with 4 additions and 3 deletions.
7 changes: 4 additions & 3 deletions client/firewall/uspfilter/conntrack/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -110,20 +110,21 @@ func NewPreallocatedIPs() *PreallocatedIPs {
return &PreallocatedIPs{
Pool: sync.Pool{
New: func() interface{} {
return make(net.IP, 16)
ip := make(net.IP, 16)
return &ip
},
},
}
}

// Get retrieves an IP from the pool
func (p *PreallocatedIPs) Get() net.IP {
return p.Pool.Get().(net.IP)
return *p.Pool.Get().(*net.IP)
}

// Put returns an IP to the pool
func (p *PreallocatedIPs) Put(ip net.IP) {
p.Pool.Put(ip)
p.Pool.Put(&ip)
}

// copyIP copies an IP address efficiently
Expand Down

0 comments on commit 84df403

Please sign in to comment.