From 9894f8d1b1e174dcf4f7dabb4f22dc5dbcb46542 Mon Sep 17 00:00:00 2001 From: Trey Dockendorf Date: Wed, 29 Jan 2020 12:35:46 -0500 Subject: [PATCH 1/2] Avoid nil pointer dereference with errors on Delete --- client.go | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/client.go b/client.go index 51d831ac..baec3132 100644 --- a/client.go +++ b/client.go @@ -160,10 +160,12 @@ func (c *APIClient) Patch(url string, payload interface{}) (*http.Response, erro // Delete performs a Delete request against the Redfish service. func (c *APIClient) Delete(url string) error { resp, err := c.runRequest("DELETE", url, nil) - resp.Body.Close() if err != nil { return err } + if resp.Body != nil { + resp.Body.Close() + } return nil } From 5a8cf19910014de86baba650d7bcc774779a699e Mon Sep 17 00:00:00 2001 From: Trey Dockendorf Date: Wed, 29 Jan 2020 17:01:33 -0500 Subject: [PATCH 2/2] Also don't operate if resp is nil --- client.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/client.go b/client.go index baec3132..48213b6e 100644 --- a/client.go +++ b/client.go @@ -163,7 +163,7 @@ func (c *APIClient) Delete(url string) error { if err != nil { return err } - if resp.Body != nil { + if resp != nil && resp.Body != nil { resp.Body.Close() } return nil