From 1c1dd16fe71bcc5d0b1dcadda05436c689f46499 Mon Sep 17 00:00:00 2001 From: Robert Sesek Date: Sun, 4 Mar 2012 01:10:59 -0500 Subject: [PATCH] Fix some fd leaks from os.Open --- src/config.go | 2 ++ src/paths.go | 1 + src/server.go | 2 ++ 3 files changed, 5 insertions(+) diff --git a/src/config.go b/src/config.go index 536bf2f..26443b2 100644 --- a/src/config.go +++ b/src/config.go @@ -36,6 +36,8 @@ func ReadFromFile(aPath string, config *Configuration) os.Error { if error != nil { return error } + defer fd.Close() + decoder := json.NewDecoder(fd) return decoder.Decode(config) } diff --git a/src/paths.go b/src/paths.go index 417828d..ac5e254 100644 --- a/src/paths.go +++ b/src/paths.go @@ -57,6 +57,7 @@ func List(the_path string) (files vector.StringVector, err os.Error) { if file_error != nil { return nil, file_error } + defer fd.Close() fileinfos, read_err := fd.Readdir(-1) if read_err != nil { diff --git a/src/server.go b/src/server.go index 508da5a..7da8aae 100644 --- a/src/server.go +++ b/src/server.go @@ -34,6 +34,8 @@ func indexHandler(response http.ResponseWriter, request *http.Request) { fmt.Print("Error opening file ", err.String(), "\n") return } + defer fd.Close() + response.Header().Set("Content-Type", "text/html") io.Copy(response, fd) } -- 2.43.5