Source file src/cmd/cgo/internal/testsanitizers/testdata/lsan1.go
1 // Copyright 2025 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 package main 6 7 /* 8 #include <stdlib.h> 9 10 int* test() { 11 return malloc(sizeof(int)); 12 } 13 14 void clearStack(int n) { 15 if (n > 0) { 16 clearStack(n - 1); 17 } 18 } 19 20 */ 21 import "C" 22 23 //go:noinline 24 func F() { 25 C.test() 26 } 27 28 func clearStack(n int) { 29 if n > 0 { 30 clearStack(n - 1) 31 } 32 } 33 34 func main() { 35 // Test should fail: memory allocated by C is leaked. 36 F() 37 clearStack(100) 38 C.clearStack(100) 39 } 40