Close HTTP client request body to prevent memory leaks.

This commit is contained in:
Adrian Gallagher
2015-03-14 16:03:05 +11:00
parent 2e13fae287
commit 6e6542001a
11 changed files with 14 additions and 14 deletions

View File

@@ -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")
@@ -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
}

View File

@@ -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")
@@ -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
}

View File

@@ -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")
@@ -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
}

View File

@@ -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")
@@ -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
}

View File

@@ -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")
@@ -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
}

View File

@@ -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)

View File

@@ -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")
@@ -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
}

View File

@@ -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")
@@ -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
}

View File

@@ -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")
@@ -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
}

View File

@@ -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")
@@ -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
}

View File

@@ -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")
@@ -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
}