Closed hbhasker closed 5 years ago
Actually on rereading this is fine. It's using NewViewFromBytes which allocates a new buffer underneath and copies b into it. Closing bug.
// NewViewFromBytes allocates a new buffer and copies in the given bytes. func NewViewFromBytes(b []byte) View { return append(View(nil), b...) }
tcpip.SlicePayload implements Get() as follows.
// Get implements Payload. func (s SlicePayload) Get(size int) ([]byte, *Error) { if size > s.Size() { size = s.Size() } return s[:size], nil }
adapters/gonet uses this to wrap a view created from a buffer passed in to the Write() call. If you follow the code eventually this slice is passed when creating a segment. Essentially we are holding a reference to a user-supplied buffer in a segment in the Netstack.