Encrypted reader wrapped in NewGetObjectReader should be closed (#6383)

This commit is contained in:
Harshavardhana 2018-08-29 19:18:00 -07:00 committed by GitHub
parent 384a862940
commit 53a0bbeb5b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 17 additions and 10 deletions

View File

@ -233,6 +233,9 @@ func (api objectAPIHandlers) SelectObjectContentHandler(w http.ResponseWriter, r
encReader = io.LimitReader(ioutil.NewSkipReader(encReader, startOffset%(64*1024)), length) encReader = io.LimitReader(ioutil.NewSkipReader(encReader, startOffset%(64*1024)), length)
cleanUp := func() { reader.Close() } cleanUp := func() { reader.Close() }
reader = NewGetObjectReader(encReader, nil, cleanUp) reader = NewGetObjectReader(encReader, nil, cleanUp)
if reader != nil {
defer reader.Close()
}
if s3Encrypted { if s3Encrypted {
w.Header().Set(crypto.SSEHeader, crypto.SSEAlgorithmAES256) w.Header().Set(crypto.SSEHeader, crypto.SSEAlgorithmAES256)
} else { } else {
@ -416,6 +419,9 @@ func (api objectAPIHandlers) GetObjectHandler(w http.ResponseWriter, r *http.Req
encReader = io.LimitReader(ioutil.NewSkipReader(encReader, startOffset%(64*1024)), length) encReader = io.LimitReader(ioutil.NewSkipReader(encReader, startOffset%(64*1024)), length)
cleanUp := func() { reader.Close() } cleanUp := func() { reader.Close() }
reader = NewGetObjectReader(encReader, nil, cleanUp) reader = NewGetObjectReader(encReader, nil, cleanUp)
if reader != nil {
defer reader.Close()
}
if s3Encrypted { if s3Encrypted {
w.Header().Set(crypto.SSEHeader, crypto.SSEAlgorithmAES256) w.Header().Set(crypto.SSEHeader, crypto.SSEAlgorithmAES256)
} else { } else {

View File

@ -170,29 +170,26 @@ func (xl xlObjects) GetObjectNInfo(ctx context.Context, bucket, object string, r
if err = lock.GetRLock(globalObjectTimeout); err != nil { if err = lock.GetRLock(globalObjectTimeout); err != nil {
return objInfo, nil, err return objInfo, nil, err
} }
objReader := &GetObjectReader{
lock: lock,
}
if err = checkGetObjArgs(ctx, bucket, object); err != nil { if err = checkGetObjArgs(ctx, bucket, object); err != nil {
return objInfo, objReader, err return objInfo, nil, err
} }
if hasSuffix(object, slashSeparator) { if hasSuffix(object, slashSeparator) {
if !xl.isObjectDir(bucket, object) { if !xl.isObjectDir(bucket, object) {
return objInfo, objReader, toObjectErr(errFileNotFound, bucket, object) return objInfo, nil, toObjectErr(errFileNotFound, bucket, object)
} }
var e error var e error
if objInfo, e = xl.getObjectInfoDir(ctx, bucket, object); e != nil { if objInfo, e = xl.getObjectInfoDir(ctx, bucket, object); e != nil {
return objInfo, objReader, toObjectErr(e, bucket, object) return objInfo, nil, toObjectErr(e, bucket, object)
} }
objReader.pr = bytes.NewBuffer(nil) objReader := NewGetObjectReader(bytes.NewReader(nil), lock, nil)
return objInfo, objReader, nil return objInfo, objReader, nil
} }
objInfo, err = xl.getObjectInfo(ctx, bucket, object) objInfo, err = xl.getObjectInfo(ctx, bucket, object)
if err != nil { if err != nil {
return objInfo, objReader, toObjectErr(err, bucket, object) return objInfo, nil, toObjectErr(err, bucket, object)
} }
startOffset, readLength := int64(0), objInfo.Size startOffset, readLength := int64(0), objInfo.Size
@ -201,10 +198,14 @@ func (xl xlObjects) GetObjectNInfo(ctx context.Context, bucket, object string, r
} }
pr, pw := io.Pipe() pr, pw := io.Pipe()
objReader.pr = pr objReader := NewGetObjectReader(pr, lock, nil)
go func() { go func() {
err := xl.getObject(ctx, bucket, object, startOffset, readLength, pw, "") err := xl.getObject(ctx, bucket, object, startOffset, readLength, pw, "")
pw.CloseWithError(err) if err != nil {
pw.CloseWithError(err)
return
}
pw.Close()
}() }()
return objInfo, objReader, nil return objInfo, objReader, nil