Przeglądaj źródła

pkg/storage: defer Close() after error handling (#2155)

Signed-off-by: Lars Lehtonen <lars.lehtonen@gmail.com>
Lars Lehtonen 2 lat temu
rodzic
commit
936dbd56ff
1 zmienionych plików z 1 dodań i 1 usunięć
  1. 1 1
      pkg/storage/s3storage.go

+ 1 - 1
pkg/storage/s3storage.go

@@ -565,13 +565,13 @@ func (s3 *S3Storage) getRange(ctx context.Context, name string, off, length int6
 		}
 	}
 	r, err := s3.client.GetObject(ctx, s3.name, name, *opts)
-	defer r.Close()
 	if err != nil {
 		if s3.isObjNotFound(err) {
 			return nil, DoesNotExistError
 		}
 		return nil, err
 	}
+	defer r.Close()
 
 	// NotFoundObject error is revealed only after first Read. This does the initial GetRequest. Prefetch this here
 	// for convenience.