Skip to content

Commit

Permalink
Merge pull request #117 from liubog2008/fix-leak
Browse files Browse the repository at this point in the history
fix(resp): fix connection leak problem of missing response body close
  • Loading branch information
timburks authored May 10, 2019
2 parents 909070f + 993a7dd commit c273e2c
Showing 1 changed file with 3 additions and 2 deletions.
5 changes: 3 additions & 2 deletions compiler/reader.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,14 @@ package compiler
import (
"errors"
"fmt"
"gopkg.in/yaml.v2"
"io/ioutil"
"log"
"net/http"
"net/url"
"path/filepath"
"strings"

yaml "gopkg.in/yaml.v2"
)

var fileCache map[string][]byte
Expand Down Expand Up @@ -90,10 +91,10 @@ func FetchFile(fileurl string) ([]byte, error) {
if err != nil {
return nil, err
}
defer response.Body.Close()
if response.StatusCode != 200 {
return nil, errors.New(fmt.Sprintf("Error downloading %s: %s", fileurl, response.Status))
}
defer response.Body.Close()
bytes, err = ioutil.ReadAll(response.Body)
if fileCacheEnable && err == nil {
fileCache[fileurl] = bytes
Expand Down

0 comments on commit c273e2c

Please sign in to comment.