From 7c26e11d6f01aeed13ff194843aa91c64463e91c Mon Sep 17 00:00:00 2001 From: Ted Yu Date: Wed, 25 Sep 2019 10:14:39 -0700 Subject: [PATCH] Properly close the file in makeFile --- pkg/volume/hostpath/host_path.go | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/pkg/volume/hostpath/host_path.go b/pkg/volume/hostpath/host_path.go index ffc4e7d7bdf..ecc66675257 100644 --- a/pkg/volume/hostpath/host_path.go +++ b/pkg/volume/hostpath/host_path.go @@ -489,7 +489,9 @@ func makeDir(pathname string) error { // If pathname already exists, whether a file or directory, no error is returned. func makeFile(pathname string) error { f, err := os.OpenFile(pathname, os.O_CREATE, os.FileMode(0644)) - defer f.Close() + if f != nil { + f.Close() + } if err != nil { if !os.IsExist(err) { return err