]> Cypherpunks repositories - gostls13.git/commitdiff
os: close fd if fd.Stat fails in Getwd
authorTobias Klauser <tklauser@distanz.ch>
Tue, 22 Sep 2020 12:48:02 +0000 (14:48 +0200)
committerTobias Klauser <tobias.klauser@gmail.com>
Tue, 22 Sep 2020 13:25:27 +0000 (13:25 +0000)
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 <tobias.klauser@gmail.com>
Run-TryBot: Tobias Klauser <tobias.klauser@gmail.com>
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
TryBot-Result: Go Bot <gobot@golang.org>

src/os/getwd.go

index f3afd8c06cf88d71a0883fe1cbcb48a4e2c521bd..f373ce937da5ce517f37f293b86f9f92a3da39cc 100644 (file)
@@ -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
                }