Skip to content

Commit f3be3a1

Browse files
Merge pull request #22 from tris/master
Fix memory corruption in io.Writer interface
2 parents 49a10eb + 40522e0 commit f3be3a1

File tree

1 file changed

+5
-1
lines changed

1 file changed

+5
-1
lines changed

splunk/v2/writer.go

+5-1
Original file line numberDiff line numberDiff line change
@@ -50,9 +50,13 @@ func (w *Writer) Write(b []byte) (int, error) {
5050
w.errors = make(chan error, bufferSize)
5151
go w.listen()
5252
})
53+
// Make a local copy of the bytearray so it doesn't get overwritten by
54+
// the next call to Write()
55+
var b2 = make([]byte, len(b))
56+
copy(b2, b)
5357
// Send the data to the channel
5458
w.dataChan <- &message{
55-
data: b,
59+
data: b2,
5660
writtenAt: time.Now(),
5761
}
5862
// We don't know if we've hit any errors yet, so just say we're good

0 commit comments

Comments
 (0)