From 9df266a6b478b63395d0b50c7f366b8931eda5e5 Mon Sep 17 00:00:00 2001 From: Nick Craig-Wood Date: Mon, 26 Mar 2018 17:17:56 +0100 Subject: [PATCH] onedrive: Fix socket leak in multipart session upload This had gone unnoticed until recently when we changed to uploading all files with a multipart session. --- backend/onedrive/onedrive.go | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/backend/onedrive/onedrive.go b/backend/onedrive/onedrive.go index c32a25bbb..1e5da9470 100644 --- a/backend/onedrive/onedrive.go +++ b/backend/onedrive/onedrive.go @@ -1125,12 +1125,14 @@ func (o *Object) uploadFragment(url string, start int64, totalSize int64, chunk err = o.fs.pacer.Call(func() (bool, error) { _, _ = chunk.Seek(0, 0) resp, err = o.fs.srv.Call(&opts) + if resp != nil { + defer fs.CheckClose(resp.Body, &err) + } retry, err := shouldRetry(resp, err) if !retry && resp != nil { if resp.StatusCode == 200 || resp.StatusCode == 201 { // we are done :) // read the item - defer fs.CheckClose(resp.Body, &err) info = &api.Item{} return false, json.NewDecoder(resp.Body).Decode(info) }