From 22c56d292e340b5e588a518d716308a339af1eda Mon Sep 17 00:00:00 2001 From: tycho garen Date: Wed, 22 Feb 2017 08:46:23 -0500 Subject: [PATCH] close open files --- host/host_darwin.go | 1 + host/host_freebsd.go | 3 +++ host/host_linux.go | 1 + host/host_openbsd.go | 2 ++ internal/common/common_linux.go | 2 +- process/process_posix.go | 2 ++ 6 files changed, 10 insertions(+), 1 deletion(-) diff --git a/host/host_darwin.go b/host/host_darwin.go index bbd134f..7b68d74 100644 --- a/host/host_darwin.go +++ b/host/host_darwin.go @@ -104,6 +104,7 @@ func Users() ([]UserStat, error) { if err != nil { return ret, err } + defer file.Close() buf, err := ioutil.ReadAll(file) if err != nil { diff --git a/host/host_freebsd.go b/host/host_freebsd.go index 74137cb..d8bd6fc 100644 --- a/host/host_freebsd.go +++ b/host/host_freebsd.go @@ -112,6 +112,7 @@ func Users() ([]UserStat, error) { if err != nil { return ret, err } + defer file.Close() buf, err := ioutil.ReadAll(file) if err != nil { @@ -180,6 +181,8 @@ func getUsersFromUtmp(utmpfile string) ([]UserStat, error) { if err != nil { return ret, err } + defer file.Close() + buf, err := ioutil.ReadAll(file) if err != nil { return ret, err diff --git a/host/host_linux.go b/host/host_linux.go index a34c67d..70d8ca2 100644 --- a/host/host_linux.go +++ b/host/host_linux.go @@ -131,6 +131,7 @@ func Users() ([]UserStat, error) { if err != nil { return nil, err } + defer file.Close() buf, err := ioutil.ReadAll(file) if err != nil { diff --git a/host/host_openbsd.go b/host/host_openbsd.go index e533d86..60d46e0 100644 --- a/host/host_openbsd.go +++ b/host/host_openbsd.go @@ -123,6 +123,8 @@ func Users() ([]UserStat, error) { if err != nil { return ret, err } + defer file.Close() + buf, err := ioutil.ReadAll(file) if err != nil { return ret, err diff --git a/internal/common/common_linux.go b/internal/common/common_linux.go index 9568106..3d0fc50 100644 --- a/internal/common/common_linux.go +++ b/internal/common/common_linux.go @@ -33,9 +33,9 @@ func NumProcs() (uint64, error) { if err != nil { return 0, err } + defer f.Close() list, err := f.Readdir(-1) - defer f.Close() if err != nil { return 0, err } diff --git a/process/process_posix.go b/process/process_posix.go index ef4b676..b22a72d 100644 --- a/process/process_posix.go +++ b/process/process_posix.go @@ -40,6 +40,8 @@ func getTerminalMap() (map[uint64]string, error) { return nil, err } } + defer ptsd.Close() + if ptsnames == nil { defer ptsd.Close() ptsnames, err = ptsd.Readdirnames(-1)