-
Notifications
You must be signed in to change notification settings - Fork 18.4k
Closed
Labels
Milestone
Description
In the program below, 'i' is treated as not escaping, yet it does escape. This can
cause crashes and memory corruption.
package main
import (
"fmt"
)
type T struct {
v *int
}
func foo(ch chan *T) {
i := 42
t := T{&i}
defer func() {
ch <- &t
}()
}
func main() {
ch := make(chan *T, 2)
foo(ch)
foo(ch)
close(ch)
for t := range ch {
fmt.Printf("%v %v\n", t, *t.v)
}
}