From 84b1182233ec25928b04c04a9bca567f552f95ae Mon Sep 17 00:00:00 2001
From: guoguangwu <guoguangwug@gmail.com>
Date: Fri, 19 Apr 2024 09:05:50 +0800
Subject: [PATCH] runtime/testdata/testprog: close files in the tidExists
 GCFairness func

Signed-off-by: guoguangwu <guoguangwug@gmail.com>
---
 src/runtime/testdata/testprog/gc.go             | 2 ++
 src/runtime/testdata/testprog/syscalls_linux.go | 4 +++-
 2 files changed, 5 insertions(+), 1 deletion(-)

diff --git a/src/runtime/testdata/testprog/gc.go b/src/runtime/testdata/testprog/gc.go
index 5dc85fbb6247c5..375efe382be0ed 100644
--- a/src/runtime/testdata/testprog/gc.go
+++ b/src/runtime/testdata/testprog/gc.go
@@ -73,6 +73,8 @@ func GCFairness() {
 		fmt.Println("OK")
 		return
 	}
+	defer f.Close()
+
 	if err != nil {
 		fmt.Println(err)
 		os.Exit(1)
diff --git a/src/runtime/testdata/testprog/syscalls_linux.go b/src/runtime/testdata/testprog/syscalls_linux.go
index 5bb98d01d5acb0..b4109052858c14 100644
--- a/src/runtime/testdata/testprog/syscalls_linux.go
+++ b/src/runtime/testdata/testprog/syscalls_linux.go
@@ -30,7 +30,9 @@ func tidExists(tid int) (exists, supported bool, err error) {
 	if err != nil {
 		return false, false, err
 	}
-	status, err := io.ReadAll(os.NewFile(uintptr(fd), statusFile))
+	f := os.NewFile(uintptr(fd), statusFile)
+	defer f.Close()
+	status, err := io.ReadAll(f)
 	if err != nil {
 		return false, false, err
 	}