Skip to content

Commit

Permalink
Close HTTP client request body to prevent memory leaks.
Browse files Browse the repository at this point in the history
  • Loading branch information
thrasher- committed Mar 14, 2015
1 parent 2e13fae commit 6e65420
Show file tree
Hide file tree
Showing 11 changed files with 14 additions and 14 deletions.
4 changes: 2 additions & 2 deletions bitfinexhttp.go
Original file line number Diff line number Diff line change
Expand Up @@ -267,6 +267,7 @@ func (b *Bitfinex) SendAuthenticatedHTTPRequest(method, path string, params map[

client := &http.Client{}
resp, err := client.Do(req)
defer resp.Body.Close()

if err != nil {
return errors.New("SendAuthenticatedHTTPRequest: Unable to send request")
Expand All @@ -283,8 +284,7 @@ func (b *Bitfinex) SendAuthenticatedHTTPRequest(method, path string, params map[
if err != nil {
return errors.New("Unable to JSON response.")
}

resp.Body.Close()

return nil
}

Expand Down
2 changes: 1 addition & 1 deletion bitstamphttp.go
Original file line number Diff line number Diff line change
Expand Up @@ -287,6 +287,7 @@ func (b *Bitstamp) SendAuthenticatedHTTPRequest(path string, values url.Values,

client := &http.Client{}
resp, err := client.Do(req)
defer resp.Body.Close()

if err != nil {
return errors.New("PostRequest: Unable to send request")
Expand All @@ -304,6 +305,5 @@ func (b *Bitstamp) SendAuthenticatedHTTPRequest(path string, values url.Values,
return errors.New("Unable to JSON response.")
}

resp.Body.Close()
return nil
}
2 changes: 1 addition & 1 deletion btcchinahttp.go
Original file line number Diff line number Diff line change
Expand Up @@ -705,6 +705,7 @@ func (b *BTCChina) SendAuthenticatedHTTPRequest(method string, params []interfac

client := &http.Client{}
resp, err := client.Do(req)
defer resp.Body.Close()

if err != nil {
return errors.New("PostRequest: Unable to send request")
Expand All @@ -716,7 +717,6 @@ func (b *BTCChina) SendAuthenticatedHTTPRequest(method string, params []interfac
log.Printf("Recv'd :%s\n", string(contents))
}

resp.Body.Close()
return nil

}
3 changes: 2 additions & 1 deletion btcehttp.go
Original file line number Diff line number Diff line change
Expand Up @@ -255,6 +255,7 @@ func (b *BTCE) SendAuthenticatedHTTPRequest(method string, values url.Values) (e

client := &http.Client{}
resp, err := client.Do(req)
defer resp.Body.Close()

if err != nil {
return errors.New("PostRequest: Unable to send request")
Expand All @@ -266,7 +267,7 @@ func (b *BTCE) SendAuthenticatedHTTPRequest(method string, values url.Values) (e
log.Printf("Recieved raw: %s\n", string(contents))
}

resp.Body.Close()

return nil

}
2 changes: 1 addition & 1 deletion btcmarkets.go
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,7 @@ func (b *BTCMarkets) SendAuthenticatedRequest(reqType, path, data string) (error

client := &http.Client{}
resp, err := client.Do(req)
defer resp.Body.Close()

if err != nil {
return errors.New("PostRequest: Unable to send request")
Expand All @@ -137,6 +138,5 @@ func (b *BTCMarkets) SendAuthenticatedRequest(reqType, path, data string) (error
log.Printf("Recieved raw: %s\n", string(contents))
}

resp.Body.Close()
return nil
}
1 change: 1 addition & 0 deletions common.go
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,7 @@ func CalculateNetProfit(amount, priceThen, priceNow, costs float64) (float64) {

func SendHTTPRequest(url string, jsonDecode bool, result interface{}) (err error) {
res, err := http.Get(url)
defer res.Body.Close()

if err != nil {
log.Println(err)
Expand Down
4 changes: 2 additions & 2 deletions huobihttp.go
Original file line number Diff line number Diff line change
Expand Up @@ -216,6 +216,7 @@ func (h *HUOBI) SendAuthenticatedRequest(method string, v url.Values) (error) {

client := &http.Client{}
resp, err := client.Do(req)
defer resp.Body.Close()

if err != nil {
return errors.New("PostRequest: Unable to send request")
Expand All @@ -226,7 +227,6 @@ func (h *HUOBI) SendAuthenticatedRequest(method string, v url.Values) (error) {
if h.Verbose {
log.Printf("Recieved raw: %s\n", string(contents))
}

resp.Body.Close()

return nil
}
2 changes: 1 addition & 1 deletion itbithttp.go
Original file line number Diff line number Diff line change
Expand Up @@ -280,6 +280,7 @@ func (i *ItBit) SendAuthenticatedHTTPRequest(method string, path string, params

client := &http.Client{}
resp, err := client.Do(req)
defer resp.Body.Close()

if err != nil {
return errors.New("SendAuthenticatedHTTPRequest: Unable to send request")
Expand All @@ -291,6 +292,5 @@ func (i *ItBit) SendAuthenticatedHTTPRequest(method string, path string, params
log.Printf("Recieved raw: %s\n", string(contents))
}

resp.Body.Close()
return nil
}
2 changes: 1 addition & 1 deletion kraken.go
Original file line number Diff line number Diff line change
Expand Up @@ -517,6 +517,7 @@ func (k *Kraken) SendAuthenticatedHTTPRequest(method string, values url.Values)

client := &http.Client{}
resp, err := client.Do(req)
defer resp.Body.Close()

if err != nil {
return nil, errors.New("SendAuthenticatedHTTPRequest: Unable to send request")
Expand All @@ -539,6 +540,5 @@ func (k *Kraken) SendAuthenticatedHTTPRequest(method string, values url.Values)
return nil, errors.New(fmt.Sprintf("Kraken error: %s", kresp.Error))
}

resp.Body.Close()
return kresp.Result, nil
}
3 changes: 1 addition & 2 deletions lakebtchttp.go
Original file line number Diff line number Diff line change
Expand Up @@ -194,6 +194,7 @@ func (l *LakeBTC) SendAuthenticatedHTTPRequest(method, params string) (err error

client := &http.Client{}
resp, err := client.Do(req)
defer resp.Body.Close()

if err != nil {
return errors.New("PostRequest: Unable to send request")
Expand All @@ -205,7 +206,5 @@ func (l *LakeBTC) SendAuthenticatedHTTPRequest(method, params string) (err error
log.Printf("Recieved raw: %s\n", string(contents))
}

resp.Body.Close()
return nil

}
3 changes: 1 addition & 2 deletions okcoinhttp.go
Original file line number Diff line number Diff line change
Expand Up @@ -426,6 +426,7 @@ func (o *OKCoin) SendAuthenticatedHTTPRequest(method string, v url.Values) (err

client := &http.Client{}
resp, err := client.Do(req)
defer resp.Body.Close()

if err != nil {
return errors.New("PostRequest: Unable to send request")
Expand All @@ -437,7 +438,5 @@ func (o *OKCoin) SendAuthenticatedHTTPRequest(method string, v url.Values) (err
log.Printf("Recieved raw: %s\n", string(contents))
}

resp.Body.Close()
return nil

}

0 comments on commit 6e65420

Please sign in to comment.