mirror of
https://github.com/fosrl/gerbil.git
synced 2026-02-08 05:56:40 +00:00
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:
@@ -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}
|
||||||
|
|||||||
Reference in New Issue
Block a user