Skip to content

cmd/gc: escape analysis bug #3545

Closed
Closed

Description

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

Activity

  1. lvdlvd commented on Apr 18, 2012

    @lvdlvd

    Comment 1:

    how annoying.   I thought about it for a bit and wrote
    http://golang.org/cl/6061043
  2. lvdlvd commented on Apr 23, 2012

    @lvdlvd

    Comment 2:

    This issue was closed by revision 5583060.

    Status changed to Fixed.

  3. lvdlvd commented on Apr 25, 2012

    @lvdlvd

    Comment 3:

    This issue was closed by revision 4318c86ac48f.

  4. added this to the Go1.0.1 milestone on Apr 14, 2015
  5. added a commit that references this issue on May 11, 2015
    cb6f9ce
  6. locked and limited conversation to collaborators on Jun 24, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions