relay: fix buffer leak on UDP read error by returning buffer to pool

When ReadFromUDP fails in readPackets, the buffer was not returned to the
sync.Pool, causing a small but persistent leak under error conditions.
Return the buffer before continuing to ensure reuse and stable memory.

Scope: minimal hotfix (no broader refactors).
This commit is contained in:
Laurence
2025-11-16 06:07:48 +00:00
parent 709df6db3e
commit b2392fb250

View File

@@ -187,6 +187,8 @@ func (s *UDPProxyServer) readPackets() {
n, remoteAddr, err := s.conn.ReadFromUDP(buf) n, remoteAddr, err := s.conn.ReadFromUDP(buf)
if err != nil { if err != nil {
logger.Error("Error reading UDP packet: %v", err) logger.Error("Error reading UDP packet: %v", err)
// Return buffer to pool on read error to avoid leaks
bufferPool.Put(buf[:1500])
continue continue
} }
s.packetChan <- Packet{data: buf[:n], remoteAddr: remoteAddr, n: n} s.packetChan <- Packet{data: buf[:n], remoteAddr: remoteAddr, n: n}