mirror of
https://github.com/minio/minio.git
synced 2024-12-23 21:55:53 -05:00
fix: a possible closer leak in SelectObjectHandler (#16598)
This commit is contained in:
parent
3a6cd4f73d
commit
e470268c7c
@ -242,7 +242,7 @@ func (api objectAPIHandlers) SelectObjectContentHandler(w http.ResponseWriter, r
|
||||
},
|
||||
actualSize,
|
||||
)
|
||||
|
||||
defer objectRSC.Close()
|
||||
s3Select, err := s3select.NewS3Select(r.Body)
|
||||
if err != nil {
|
||||
if serr, ok := err.(s3select.SelectError); ok {
|
||||
@ -3124,7 +3124,7 @@ func (api objectAPIHandlers) PostRestoreObjectHandler(w http.ResponseWriter, r *
|
||||
},
|
||||
actualSize,
|
||||
)
|
||||
|
||||
defer objectRSC.Close()
|
||||
if err = rreq.SelectParameters.Open(objectRSC); err != nil {
|
||||
if serr, ok := err.(s3select.SelectError); ok {
|
||||
encodedErrorResponse := encodeResponse(APIErrorResponse{
|
||||
|
@ -698,6 +698,11 @@ type ObjectReadSeekCloser struct {
|
||||
size int64 // actual object size regardless of compression/encryption
|
||||
offset int64
|
||||
reader io.ReadCloser
|
||||
|
||||
// reader can be closed idempotently multiple times
|
||||
closerOnce sync.Once
|
||||
// Error storing reader.Close()
|
||||
closerErr error
|
||||
}
|
||||
|
||||
// NewObjectReadSeekCloser creates a new ObjectReadSeekCloser.
|
||||
@ -749,12 +754,11 @@ func (rsc *ObjectReadSeekCloser) Read(p []byte) (n int, err error) {
|
||||
// object for reading and a subsequent Close call is required to ensure
|
||||
// resources are freed.
|
||||
func (rsc *ObjectReadSeekCloser) Close() error {
|
||||
if rsc.reader != nil {
|
||||
err := rsc.reader.Close()
|
||||
if err == nil {
|
||||
rsc.closerOnce.Do(func() {
|
||||
if rsc.reader != nil {
|
||||
rsc.closerErr = rsc.reader.Close()
|
||||
rsc.reader = nil
|
||||
}
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
})
|
||||
return rsc.closerErr
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user