forked from quic-go/quic-go
copy the slice passed to stream.Write
This commit is contained in:
@@ -160,7 +160,8 @@ func (s *stream) Write(p []byte) (int, error) {
|
||||
s.mutex.Lock()
|
||||
defer s.mutex.Unlock()
|
||||
|
||||
s.dataForWriting = p
|
||||
s.dataForWriting = make([]byte, len(p))
|
||||
copy(s.dataForWriting, p)
|
||||
|
||||
s.session.scheduleSending()
|
||||
|
||||
|
||||
@@ -346,6 +346,18 @@ var _ = Describe("Stream", func() {
|
||||
It("getDataForWriting returns nil if no data is available", func() {
|
||||
Expect(str.getDataForWriting(1000)).To(BeNil())
|
||||
})
|
||||
|
||||
It("copies the slice while writing", func() {
|
||||
s := []byte("foo")
|
||||
go func() {
|
||||
n, err := str.Write(s)
|
||||
Expect(err).ToNot(HaveOccurred())
|
||||
Expect(n).To(Equal(3))
|
||||
}()
|
||||
Eventually(func() protocol.ByteCount { return str.lenOfDataForWriting() }).ShouldNot(BeZero())
|
||||
s[0] = 'v'
|
||||
Expect(str.getDataForWriting(3)).To(Equal([]byte("foo")))
|
||||
})
|
||||
})
|
||||
|
||||
Context("closing", func() {
|
||||
|
||||
Reference in New Issue
Block a user