Skip to content

Commit

Permalink
Fix buffer usage
Browse files Browse the repository at this point in the history
  • Loading branch information
nekohasekai committed Dec 8, 2023
1 parent fed8d42 commit a9d165b
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 3 deletions.
4 changes: 2 additions & 2 deletions shadowaead_2022/protocol.go
Original file line number Diff line number Diff line change
Expand Up @@ -294,7 +294,7 @@ func (c *clientConn) writeRequest(payload []byte) error {
payloadLen := len(payload)
variableLengthHeaderLen += payloadLen
common.Must(binary.Write(fixedLengthBuffer, binary.BigEndian, uint16(variableLengthHeaderLen)))
writer.WriteChunk(header, fixedLengthBuffer.Slice())
writer.WriteChunk(header, fixedLengthBuffer.Bytes())

variableLengthBuffer := buf.NewSize(variableLengthHeaderLen)
err = M.SocksaddrSerializer.WriteAddrPort(variableLengthBuffer, c.destination)
Expand All @@ -308,7 +308,7 @@ func (c *clientConn) writeRequest(payload []byte) error {
if payloadLen > 0 {
common.Must1(variableLengthBuffer.Write(payload[:payloadLen]))
}
writer.WriteChunk(header, variableLengthBuffer.Slice())
writer.WriteChunk(header, variableLengthBuffer.Bytes())
variableLengthBuffer.Release()

err = writer.BufferedWriter(header.Len()).Flush()
Expand Down
2 changes: 1 addition & 1 deletion shadowaead_2022/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -287,7 +287,7 @@ func (c *serverConn) writeResponse(payload []byte) (n int, err error) {
common.Must1(headerFixedChunk.Write(c.requestSalt))
common.Must(binary.Write(headerFixedChunk, binary.BigEndian, uint16(payloadLen)))

writer.WriteChunk(header, headerFixedChunk.Slice())
writer.WriteChunk(header, headerFixedChunk.Bytes())
headerFixedChunk.Release()
c.requestSalt = nil

Expand Down

0 comments on commit a9d165b

Please # to comment.