Skip to content

cmd/gc: escape analysis bug #3545

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

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