Skip to content

Commit

Permalink
S3: Correctly defer closing response body, unless nil
Browse files Browse the repository at this point in the history
  • Loading branch information
mattheath committed Mar 31, 2014
1 parent 20a8220 commit 51ed81f
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion s3/s3.go
Original file line number Diff line number Diff line change
Expand Up @@ -168,11 +168,15 @@ func (b *Bucket) DelBucket() (err error) {
// See http://goo.gl/isCO7 for details.
func (b *Bucket) Get(path string) (data []byte, err error) {
body, err := b.GetReader(path)
defer func() {
if body != nil {
body.Close()
}
}()
if err != nil {
return nil, err
}
data, err = ioutil.ReadAll(body)
body.Close()
return data, err
}

Expand Down

0 comments on commit 51ed81f

Please sign in to comment.