From 1d9fa029c2478df7f7dcce3cabdd953dc4a0568e Mon Sep 17 00:00:00 2001 From: tobyxdd Date: Tue, 14 Feb 2023 21:30:45 -0800 Subject: [PATCH] fix: set serverAddrs to nil when closing an ObfsUDPHopClientPacketConn to prevent memory leaks --- core/pktconns/udp/hop.go | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/core/pktconns/udp/hop.go b/core/pktconns/udp/hop.go index 4458131..a893514 100644 --- a/core/pktconns/udp/hop.go +++ b/core/pktconns/udp/hop.go @@ -204,6 +204,9 @@ func (c *ObfsUDPHopClientPacketConn) ReadFrom(b []byte) (int, net.Addr, error) { func (c *ObfsUDPHopClientPacketConn) WriteTo(b []byte, addr net.Addr) (int, error) { c.connMutex.RLock() defer c.connMutex.RUnlock() + if c.closed { + return 0, net.ErrClosed + } /* // Check if the address is the server address if addr.String() != c.serverAddr.String() { @@ -229,6 +232,7 @@ func (c *ObfsUDPHopClientPacketConn) Close() error { err := c.currentConn.Close() close(c.closeChan) c.closed = true + c.serverAddrs = nil // For GC return err }