Last active
February 16, 2019 04:59
-
-
Save mdempsky/f24d1ad476daedc0e444b23b2159c0c0 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$ go tool compile -m r.go | grep -e leaking -e new.int | |
r.go:4:12: leaking param: f to result ~r1 level=1 | |
r.go:10:10: new(int) escapes to heap | |
r.go:26:10: F2 new(int) does not escape | |
$ cat r.go | |
package p | |
//go:noinline | |
func call1(f func() error) error { | |
// Leaks *f to result. | |
return f() | |
} | |
func F1() error { | |
y := new(int) | |
return call1(func() error { | |
y = nil | |
return nil | |
}) | |
} | |
//go:noinline | |
func call2(f func() error) error { | |
// No param leakage. | |
f() | |
return nil | |
} | |
func F2() error { | |
y := new(int) | |
return call2(func() error { | |
y = nil | |
return nil | |
}) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment