From 7baecf3a615dc375287bfd11cc823bec13ca4d15 Mon Sep 17 00:00:00 2001 From: Tobias Lindberg Date: Wed, 19 May 2021 19:53:54 +0200 Subject: [PATCH] moving defer to when error check has passed go-staticcheck: should check returned error before deferring commandAllowListFile.Close() (SA5001) --- src/CommandSupport.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/CommandSupport.go b/src/CommandSupport.go index 6a26b08..d581586 100644 --- a/src/CommandSupport.go +++ b/src/CommandSupport.go @@ -140,10 +140,10 @@ func initCommandAllowList() { if len(allowList) == 0 { var allowListFile []string commandAllowListFile, err := os.Open(commandAllowListLocation) - defer commandAllowListFile.Close() if err != nil { log.Println("[error] getAllowList error with COMMANDS_ALLOWLIST: " + commandAllowListLocation + " not found and will be ignored") } else { + defer commandAllowListFile.Close() byteValue, err := ioutil.ReadAll(commandAllowListFile) if err != nil { log.Println("[error] getAllowList error while reading COMMANDS_ALLOWLIST: " + commandAllowListLocation + " it will be ignored")