Skip to content

Commit

Permalink
bug: fix memory corruption for Conn.Next (#649)
Browse files Browse the repository at this point in the history
Fixes #648 

---------

Co-authored-by: zhongweikang <zhongweikang@sfmail.sf-express.com>
  • Loading branch information
zhongweikang and zhongweikang authored Nov 6, 2024
1 parent 2e261de commit cbf7c6a
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 6 deletions.
6 changes: 3 additions & 3 deletions connection_unix.go
Original file line number Diff line number Diff line change
Expand Up @@ -325,11 +325,11 @@ func (c *conn) Next(n int) (buf []byte, err error) {
}
head, tail := c.inboundBuffer.Peek(n)
defer c.inboundBuffer.Discard(n) //nolint:errcheck
if len(head) >= n {
return head[:n], err
}
c.loop.cache.Reset()
c.loop.cache.Write(head)
if len(head) >= n {
return c.loop.cache.Bytes(), err
}
c.loop.cache.Write(tail)
if inBufferLen >= n {
return c.loop.cache.Bytes(), err
Expand Down
6 changes: 3 additions & 3 deletions connection_windows.go
Original file line number Diff line number Diff line change
Expand Up @@ -164,11 +164,11 @@ func (c *conn) Next(n int) (buf []byte, err error) {
}
head, tail := c.inboundBuffer.Peek(n)
defer c.inboundBuffer.Discard(n) //nolint:errcheck
if len(head) >= n {
return head[:n], err
}
c.loop.cache.Reset()
c.loop.cache.Write(head)
if len(head) >= n {
return c.loop.cache.Bytes(), err
}
c.loop.cache.Write(tail)
if inBufferLen >= n {
return c.loop.cache.Bytes(), err
Expand Down

0 comments on commit cbf7c6a

Please sign in to comment.