From ebd3723a065d21ed1fcd7e15867e79b5cbaac32e Mon Sep 17 00:00:00 2001 From: Alexander Neumann Date: Sun, 21 Aug 2016 16:15:24 +0200 Subject: [PATCH] Properly close the minio object on Stat() Closes #544 --- src/restic/backend/s3/s3.go | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/src/restic/backend/s3/s3.go b/src/restic/backend/s3/s3.go index 6ea1040f5..c4e1aae54 100644 --- a/src/restic/backend/s3/s3.go +++ b/src/restic/backend/s3/s3.go @@ -182,15 +182,26 @@ func (be s3) Save(h backend.Handle, p []byte) (err error) { } // Stat returns information about a blob. -func (be s3) Stat(h backend.Handle) (backend.BlobInfo, error) { +func (be s3) Stat(h backend.Handle) (bi backend.BlobInfo, err error) { debug.Log("s3.Stat", "%v", h) + path := be.s3path(h.Type, h.Name) - obj, err := be.client.GetObject(be.bucketname, path) + var obj *minio.Object + + obj, err = be.client.GetObject(be.bucketname, path) if err != nil { debug.Log("s3.Stat", "GetObject() err %v", err) return backend.BlobInfo{}, err } + // make sure that the object is closed properly. + defer func() { + e := obj.Close() + if err == nil { + err = e + } + }() + fi, err := obj.Stat() if err != nil { debug.Log("s3.Stat", "Stat() err %v", err)