瀏覽代碼

registry/session: fix panic in GetRemoteImageLayer

Docker-DCO-1.1-Signed-off-by: Cristian Staretu <cristian.staretu@gmail.com> (github: unclejack)
unclejack 11 年之前
父節點
當前提交
9c413e3e6f
共有 1 個文件被更改,包括 3 次插入1 次删除
  1. 3 1
      registry/session.go

+ 3 - 1
registry/session.go

@@ -167,7 +167,9 @@ func (r *Session) GetRemoteImageLayer(imgID, registry string, token []string, im
 	for i := 1; i <= retries; i++ {
 		res, client, err = r.doRequest(req)
 		if err != nil {
-			res.Body.Close()
+			if res.Body != nil {
+				res.Body.Close()
+			}
 			if i == retries {
 				return nil, fmt.Errorf("Server error: Status %d while fetching image layer (%s)",
 					res.StatusCode, imgID)