Skip to content

Commit

Permalink
defer if res and body not nil (even if there is err)
Browse files Browse the repository at this point in the history
  • Loading branch information
noambergIL committed Dec 29, 2020
1 parent 83b6d78 commit 31629ef
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 8 deletions.
1 change: 0 additions & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ require (
github.com/ethereum/go-ethereum v1.9.6
github.com/fjl/memsize v0.0.0-20190710130421-bcb5799ab5e5 // indirect
github.com/gballet/go-libpcsclite v0.0.0-20190607065134-2772fd86a8ff // indirect
github.com/go-stack/stack v1.8.0 // indirect
github.com/google/go-cmp v0.3.1
github.com/huin/goupnp v1.0.0 // indirect
github.com/jackpal/go-nat-pmp v1.0.1 // indirect
Expand Down
11 changes: 4 additions & 7 deletions services/management/adapter/file_provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -79,20 +79,17 @@ func (mp *FileProvider) generatePath(referenceTime primitives.TimestampSeconds)

func (mp *FileProvider) readUrl(path string) ([]byte, error) {
res, err := mp.client.Get(path)
if res != nil && res.Body != nil {
defer res.Body.Close()
}

if err != nil || res == nil {
return nil, errors.Wrapf(err, "Failed http get of url %s", path)
} else if res.ContentLength > 0 && uint32(res.ContentLength) > mp.config.ManagementMaxFileSize() { // TODO when no length given find other way ?
return nil, errors.Wrapf(err, "Failed http get response too big %d", res.ContentLength)
}

contents, err := ioutil.ReadAll(res.Body)
if err != nil {
return nil, errors.Wrapf(err, "could not read http body")
}
defer res.Body.Close()

return contents, err
return ioutil.ReadAll(res.Body)
}

func (mp *FileProvider) readFile(filePath string) ([]byte, error) {
Expand Down

0 comments on commit 31629ef

Please sign in to comment.