Guest User

Untitled

a guest
Feb 15th, 2019
114
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.56 KB | None | 0 0
  1. $ go tool compile -m r.go | grep -e leaking -e new.int
  2. r.go:4:12: leaking param: f to result ~r1 level=1
  3. r.go:10:10: new(int) escapes to heap
  4. r.go:26:10: F2 new(int) does not escape
  5.  
  6.  
  7. $ cat r.go
  8. package p
  9.  
  10. //go:noinline
  11. func call1(f func() error) error {
  12. // Leaks *f to result.
  13. return f()
  14. }
  15.  
  16. func F1() error {
  17. y := new(int)
  18. return call1(func() error {
  19. y = nil
  20. return nil
  21. })
  22. }
  23.  
  24.  
  25. //go:noinline
  26. func call2(f func() error) error {
  27. // No param leakage.
  28. f()
  29. return nil
  30. }
  31.  
  32. func F2() error {
  33. y := new(int)
  34. return call2(func() error {
  35. y = nil
  36. return nil
  37. })
  38. }
Add Comment
Please, Sign In to add comment