From f846946810c02901a0b5769a4db1f4c048ebdeef Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E4=B8=96=E7=95=8C?= Date: Mon, 25 Mar 2024 01:53:37 +0800 Subject: [PATCH] Minor fixes --- hysteria/packet.go | 5 +++++ hysteria/packet_wait.go | 4 ++-- hysteria2/packet.go | 5 +++++ hysteria2/packet_wait.go | 4 ++-- tuic/packet.go | 5 +++++ tuic/packet_wait.go | 4 ++-- 6 files changed, 21 insertions(+), 6 deletions(-) diff --git a/hysteria/packet.go b/hysteria/packet.go index daa6208..a2689c9 100644 --- a/hysteria/packet.go +++ b/hysteria/packet.go @@ -400,6 +400,11 @@ func (d *udpDefragger) feed(m *udpMessage) *udpMessage { } item.messages = nil return newMessage + } else { + newMessage.release() + for _, message := range item.messages { + message.releaseMessage() + } } item.messages = nil return nil diff --git a/hysteria/packet_wait.go b/hysteria/packet_wait.go index f1c54ff..6476c36 100644 --- a/hysteria/packet_wait.go +++ b/hysteria/packet_wait.go @@ -20,11 +20,11 @@ func (c *udpPacketConn) WaitReadPacket() (buffer *buf.Buffer, destination M.Sock if c.readWaitOptions.NeedHeadroom() { buffer = c.readWaitOptions.NewPacketBuffer() _, err = buffer.Write(p.data.Bytes()) + p.releaseMessage() if err != nil { buffer.Release() - return nil, M.Socksaddr{}, err + return } - p.releaseMessage() c.readWaitOptions.PostReturn(buffer) } else { buffer = p.data diff --git a/hysteria2/packet.go b/hysteria2/packet.go index f77ab33..f577b15 100644 --- a/hysteria2/packet.go +++ b/hysteria2/packet.go @@ -392,6 +392,11 @@ func (d *udpDefragger) feed(m *udpMessage) *udpMessage { } item.messages = nil return newMessage + } else { + newMessage.releaseMessage() + for _, message := range item.messages { + message.releaseMessage() + } } item.messages = nil return nil diff --git a/hysteria2/packet_wait.go b/hysteria2/packet_wait.go index bbaa296..a183012 100644 --- a/hysteria2/packet_wait.go +++ b/hysteria2/packet_wait.go @@ -20,11 +20,11 @@ func (c *udpPacketConn) WaitReadPacket() (buffer *buf.Buffer, destination M.Sock if c.readWaitOptions.NeedHeadroom() { buffer = c.readWaitOptions.NewPacketBuffer() _, err = buffer.Write(p.data.Bytes()) + p.releaseMessage() if err != nil { buffer.Release() - return nil, M.Socksaddr{}, err + return } - p.releaseMessage() c.readWaitOptions.PostReturn(buffer) } else { buffer = p.data diff --git a/tuic/packet.go b/tuic/packet.go index ecc15fe..6eb07bf 100644 --- a/tuic/packet.go +++ b/tuic/packet.go @@ -437,6 +437,11 @@ func (d *udpDefragger) feed(m *udpMessage) *udpMessage { } item.messages = nil return newMessage + } else { + newMessage.releaseMessage() + for _, message := range item.messages { + message.releaseMessage() + } } item.messages = nil return nil diff --git a/tuic/packet_wait.go b/tuic/packet_wait.go index 88f3066..57c57f8 100644 --- a/tuic/packet_wait.go +++ b/tuic/packet_wait.go @@ -19,12 +19,12 @@ func (c *udpPacketConn) WaitReadPacket() (buffer *buf.Buffer, destination M.Sock destination = p.destination if c.readWaitOptions.NeedHeadroom() { buffer = c.readWaitOptions.NewPacketBuffer() + p.releaseMessage() _, err = buffer.Write(p.data.Bytes()) if err != nil { buffer.Release() - return nil, M.Socksaddr{}, err + return } - p.releaseMessage() c.readWaitOptions.PostReturn(buffer) } else { buffer = p.data