From bdc8240507007e98bdaf41a5fba519e4ce4edf44 Mon Sep 17 00:00:00 2001 From: Vincent Demeester Date: Tue, 23 May 2017 12:48:22 -0700 Subject: [PATCH] Fix `request.SockRequestRaw` error check We should check for error before reading the response (response can be nil, and thus this would panic) Signed-off-by: Vincent Demeester Upstream-commit: 45e0376ea361811b2f5d0653a6b103dd39653371 Component: engine --- components/engine/integration-cli/request/request.go | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/components/engine/integration-cli/request/request.go b/components/engine/integration-cli/request/request.go index cb0e39953e..be3628b9b2 100644 --- a/components/engine/integration-cli/request/request.go +++ b/components/engine/integration-cli/request/request.go @@ -217,13 +217,14 @@ func SockRequestRaw(method, endpoint string, data io.Reader, ct, daemon string, } resp, err := client.Do(req) + if err != nil { + client.Close() + return resp, nil, err + } body := ioutils.NewReadCloserWrapper(resp.Body, func() error { defer resp.Body.Close() return client.Close() }) - if err != nil { - client.Close() - } return resp, body, err }