Skip to content

Commit f395e87

Browse files
committed
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>
1 parent 16e430e commit f395e87

File tree

1 file changed

+5
-2
lines changed

1 file changed

+5
-2
lines changed

src/io/multi_test.go

+5-2
Original file line numberDiff line numberDiff line change
@@ -239,14 +239,17 @@ func TestMultiReaderFinalEOF(t *testing.T) {
239239
func TestMultiReaderFreesExhaustedReaders(t *testing.T) {
240240
var mr Reader
241241
closed := make(chan struct{})
242-
{
242+
// The closure ensures that we don't have a live reference to buf1
243+
// on our stack after MultiReader is inlined (Issue 18819). This
244+
// is a work around for a limitation in liveness analysis.
245+
func() {
243246
buf1 := bytes.NewReader([]byte("foo"))
244247
buf2 := bytes.NewReader([]byte("bar"))
245248
mr = MultiReader(buf1, buf2)
246249
runtime.SetFinalizer(buf1, func(*bytes.Reader) {
247250
close(closed)
248251
})
249-
}
252+
}()
250253

251254
buf := make([]byte, 4)
252255
if n, err := ReadFull(mr, buf); err != nil || string(buf) != "foob" {

0 commit comments

Comments
 (0)