1
0
mirror of https://github.com/golang/go synced 2024-11-23 16:20:04 -07:00

io: fix test when MultiReader is inlined with -l=3

This ensures there isn't a live reference to buf1 on our stack
when MultiReader is inlined.

Fixes #18819.

Change-Id: I96a8cdc1ffad8f8a10c0ddcbf0299005f3176b61
Reviewed-on: https://go-review.googlesource.com/35931
Run-TryBot: David Lazar <lazard@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Austin Clements <austin@google.com>
Reviewed-by: Russ Cox <rsc@golang.org>
This commit is contained in:
David Lazar 2017-01-27 15:24:48 -05:00
parent 16e430e1ef
commit f395e87888

View File

@ -239,14 +239,17 @@ func TestMultiReaderFinalEOF(t *testing.T) {
func TestMultiReaderFreesExhaustedReaders(t *testing.T) {
var mr Reader
closed := make(chan struct{})
{
// The closure ensures that we don't have a live reference to buf1
// on our stack after MultiReader is inlined (Issue 18819). This
// is a work around for a limitation in liveness analysis.
func() {
buf1 := bytes.NewReader([]byte("foo"))
buf2 := bytes.NewReader([]byte("bar"))
mr = MultiReader(buf1, buf2)
runtime.SetFinalizer(buf1, func(*bytes.Reader) {
close(closed)
})
}
}()
buf := make([]byte, 4)
if n, err := ReadFull(mr, buf); err != nil || string(buf) != "foob" {