Skip to content

Commit cbf7c6a

Browse files
zhongweikangzhongweikang
and
zhongweikang
authored
bug: fix memory corruption for Conn.Next (#649)
Fixes #648 --------- Co-authored-by: zhongweikang <[email protected]>
1 parent 2e261de commit cbf7c6a

File tree

2 files changed

+6
-6
lines changed

2 files changed

+6
-6
lines changed

connection_unix.go

+3-3
Original file line numberDiff line numberDiff line change
@@ -325,11 +325,11 @@ func (c *conn) Next(n int) (buf []byte, err error) {
325325
}
326326
head, tail := c.inboundBuffer.Peek(n)
327327
defer c.inboundBuffer.Discard(n) //nolint:errcheck
328-
if len(head) >= n {
329-
return head[:n], err
330-
}
331328
c.loop.cache.Reset()
332329
c.loop.cache.Write(head)
330+
if len(head) >= n {
331+
return c.loop.cache.Bytes(), err
332+
}
333333
c.loop.cache.Write(tail)
334334
if inBufferLen >= n {
335335
return c.loop.cache.Bytes(), err

connection_windows.go

+3-3
Original file line numberDiff line numberDiff line change
@@ -164,11 +164,11 @@ func (c *conn) Next(n int) (buf []byte, err error) {
164164
}
165165
head, tail := c.inboundBuffer.Peek(n)
166166
defer c.inboundBuffer.Discard(n) //nolint:errcheck
167-
if len(head) >= n {
168-
return head[:n], err
169-
}
170167
c.loop.cache.Reset()
171168
c.loop.cache.Write(head)
169+
if len(head) >= n {
170+
return c.loop.cache.Bytes(), err
171+
}
172172
c.loop.cache.Write(tail)
173173
if inBufferLen >= n {
174174
return c.loop.cache.Bytes(), err

0 commit comments

Comments
 (0)