Skip to content

cmd/gc: escape analysis bug #3545

Closed
Closed
@rsc

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

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions