Source file src/cmd/cgo/internal/testsanitizers/testdata/arena_fail.go

     1  // Copyright 2022 The Go Authors. All rights reserved.
     2  // Use of this source code is governed by a BSD-style
     3  // license that can be found in the LICENSE file.
     4  
     5  //go:build goexperiment.arenas
     6  
     7  package main
     8  
     9  import "arena"
    10  
    11  func main() {
    12  	a := arena.NewArena()
    13  	x := arena.New[[200]byte](a)
    14  	x[0] = 9
    15  	a.Free()
    16  	// Use after free.
    17  	//
    18  	// ASAN should detect this deterministically as Free
    19  	// should poison the arena memory.
    20  	//
    21  	// MSAN should detect that this access is to freed
    22  	// memory. This may crash with an "accessed freed arena
    23  	// memory" error before MSAN gets a chance, but if MSAN
    24  	// was not enabled there would be a chance that this
    25  	// could fail to crash on its own.
    26  	println(x[0])
    27  }
    28  

View as plain text