diff --git a/pkg/services/accesscontrol/database/policies.go b/pkg/services/accesscontrol/database/policies.go index 6fec2c2c483..235d301b69c 100644 --- a/pkg/services/accesscontrol/database/policies.go +++ b/pkg/services/accesscontrol/database/policies.go @@ -42,6 +42,9 @@ func GetAccessPolicies(ctx context.Context, orgID int64, sql *session.SessionDB, if err != nil { return nil, err } + defer func() { + _ = rows.Close() + }() created := time.Now() updated := time.Now() diff --git a/pkg/services/playlist/playlistimpl/xorm_store.go b/pkg/services/playlist/playlistimpl/xorm_store.go index 07c1ce548fd..8970ba15747 100644 --- a/pkg/services/playlist/playlistimpl/xorm_store.go +++ b/pkg/services/playlist/playlistimpl/xorm_store.go @@ -222,6 +222,11 @@ func (s *sqlStore) ListAll(ctx context.Context, orgId int64) ([]playlist.Playlis if err != nil { return nil, err } + + defer func() { + _ = rows.Close() + }() + for rows.Next() { err = rows.Scan(&playlistId, &itemType, &itemValue) if err != nil { diff --git a/pkg/storage/unified/search/document.go b/pkg/storage/unified/search/document.go index b2d6bf01f77..78836bef06e 100644 --- a/pkg/storage/unified/search/document.go +++ b/pkg/storage/unified/search/document.go @@ -29,6 +29,11 @@ func (s *StandardDocumentBuilders) GetDocumentBuilders() ([]resource.DocumentBui if err != nil { return nil, err } + + defer func() { + _ = rows.Close() + }() + for rows.Next() { info := &dashboard.DatasourceQueryResult{} err = rows.Scan(&info.UID, &info.Type, &info.Name, &info.IsDefault) diff --git a/pkg/storage/unified/sql/backend.go b/pkg/storage/unified/sql/backend.go index e11bbdcefcc..0e8f45d173a 100644 --- a/pkg/storage/unified/sql/backend.go +++ b/pkg/storage/unified/sql/backend.go @@ -146,6 +146,11 @@ func (b *backend) Namespaces(ctx context.Context) ([]string, error) { if err != nil { return err } + + defer func() { + _ = rows.Close() + }() + for rows.Next() { var ns string err = rows.Scan(&ns) @@ -155,8 +160,7 @@ func (b *backend) Namespaces(ctx context.Context) ([]string, error) { namespaces = append(namespaces, ns) } - err = rows.Close() - return err + return nil }) return namespaces, err @@ -679,7 +683,7 @@ func (b *backend) poll(ctx context.Context, grp string, res string, since int64, nextRV = rec.ResourceVersion prevRV := rec.PreviousRV if prevRV == nil { - *prevRV = int64(0) + prevRV = new(int64) } stream <- &resource.WrittenEvent{ WriteEvent: resource.WriteEvent{ diff --git a/pkg/storage/unified/sql/dbutil/dbutil.go b/pkg/storage/unified/sql/dbutil/dbutil.go index 03e6fbe0be7..f17b83cf335 100644 --- a/pkg/storage/unified/sql/dbutil/dbutil.go +++ b/pkg/storage/unified/sql/dbutil/dbutil.go @@ -165,6 +165,10 @@ func Query[T any](ctx context.Context, x db.ContextExecer, tmpl *template.Templa return nil, err } + defer func() { + _ = rows.Close() + }() + var ret []T for rows.Next() { v, err := scanRow(rows, req) diff --git a/pkg/storage/unified/sql/queries.go b/pkg/storage/unified/sql/queries.go index 78afce6439d..7ce060e07a7 100644 --- a/pkg/storage/unified/sql/queries.go +++ b/pkg/storage/unified/sql/queries.go @@ -101,7 +101,7 @@ func (r *sqlResourceHistoryPollRequest) Validate() error { func (r *sqlResourceHistoryPollRequest) Results() (*historyPollResponse, error) { prevRV := r.Response.PreviousRV if prevRV == nil { - *prevRV = int64(0) + prevRV = new(int64) } return &historyPollResponse{ Key: resource.ResourceKey{