From 1dd79cf684a4939adf2e00b6e2e8657569a7f894 Mon Sep 17 00:00:00 2001 From: Liang Ding Date: Mon, 26 Oct 2015 14:19:46 +0800 Subject: [PATCH] Fix copy directory resource leak --- util/file.go | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/util/file.go b/util/file.go index fc7c18f..4859a42 100644 --- a/util/file.go +++ b/util/file.go @@ -123,8 +123,17 @@ func (*myfile) CopyDir(source string, dest string) (err error) { return err } - directory, _ := os.Open(source) + directory, err := os.Open(source) + if err != nil { + return err + } + + defer directory.Close() + objects, err := directory.Readdir(-1) + if err != nil { + return err + } for _, obj := range objects { srcFilePath := filepath.Join(source, obj.Name())