cmd/gc: escape analysis bug #3545

Closed
rsc opened this Issue Apr 18, 2012 · 3 comments

Comments

Projects
None yet
3 participants
Contributor

rsc commented Apr 18, 2012

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)
       }
}

lvdlvd commented Apr 18, 2012

Comment 1:

how annoying.   I thought about it for a bit and wrote
http://golang.org/cl/6061043

lvdlvd commented Apr 23, 2012

Comment 2:

This issue was closed by revision 5583060.

Status changed to Fixed.

lvdlvd commented Apr 25, 2012

Comment 3:

This issue was closed by revision 4318c86ac48f.

@rsc rsc added fixed labels Apr 25, 2012

@rsc rsc added this to the Go1.0.1 milestone Apr 14, 2015

@rsc rsc removed the go1.0.1 label Apr 14, 2015

rsc added a commit that referenced this issue May 11, 2015

[release-branch.go1] cmd/gc: fix addresses escaping through closures …
…called in-place.

««« backport a890477d3dfb
cmd/gc: fix addresses escaping through closures called in-place.

Fixes #3545.

R=rsc
CC=golang-dev
https://golang.org/cl/6061043

»»»

@gopherbot gopherbot locked and limited conversation to collaborators Jun 24, 2016

This issue was closed.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.