From: Tobias Klauser Date: Tue, 22 Sep 2020 12:48:02 +0000 (+0200) Subject: os: close fd if fd.Stat fails in Getwd X-Git-Tag: go1.16beta1~973 X-Git-Url: http://www.git.cypherpunks.su/?a=commitdiff_plain;h=0d83fe68a843df2113d0adaac9ac6299a1c2cdad;p=gostls13.git os: close fd if fd.Stat fails in Getwd Avoid leaking fd in case fd.Stat() fails in the fall back implementation of Getwd. Change-Id: I8656d42e8dbc8893b7159873f173d6bf0d4febe6 Reviewed-on: https://go-review.googlesource.com/c/go/+/256221 Trust: Tobias Klauser Run-TryBot: Tobias Klauser Reviewed-by: Brad Fitzpatrick TryBot-Result: Go Bot --- diff --git a/src/os/getwd.go b/src/os/getwd.go index f3afd8c06c..f373ce937d 100644 --- a/src/os/getwd.go +++ b/src/os/getwd.go @@ -112,10 +112,10 @@ func Getwd() (dir string, err error) { Found: pd, err := fd.Stat() + fd.Close() if err != nil { return "", err } - fd.Close() if SameFile(pd, root) { break }