[lbry] rpcclient: fix http response resource leaking

This commit is contained in:
Roy Lee 2022-05-24 00:00:31 -07:00
parent fb3ef35189
commit 096dd3ff75

View file

@ -803,6 +803,7 @@ func (c *Client) handleSendPostMessage(jReq *jsonRequest) {
time.Sleep(backoff) time.Sleep(backoff)
continue continue
} }
defer httpResponse.Body.Close()
break break
} }
if err != nil { if err != nil {
@ -810,9 +811,8 @@ func (c *Client) handleSendPostMessage(jReq *jsonRequest) {
return return
} }
// Read the raw bytes and close the response. // Read the raw bytes from the response.
respBytes, err := ioutil.ReadAll(httpResponse.Body) respBytes, err := ioutil.ReadAll(httpResponse.Body)
httpResponse.Body.Close()
if err != nil { if err != nil {
err = fmt.Errorf("error reading json reply: %v", err) err = fmt.Errorf("error reading json reply: %v", err)
jReq.responseChan <- &Response{err: err} jReq.responseChan <- &Response{err: err}
@ -1386,6 +1386,7 @@ func dial(config *ConnConfig) (*websocket.Conn, error) {
// cases above apply. // cases above apply.
return nil, errors.New(resp.Status) return nil, errors.New(resp.Status)
} }
resp.Body.Close()
return wsConn, nil return wsConn, nil
} }