Skip to content

Commit

Permalink
fix(ecocredit): close iterators (#1173)
Browse files Browse the repository at this point in the history
Co-authored-by: tyler <tylergoodman@Tylers-MacBook-Pro.local>
  • Loading branch information
technicallyty and tyler authored Jun 9, 2022
1 parent b1dee38 commit cf969fd
Show file tree
Hide file tree
Showing 11 changed files with 14 additions and 0 deletions.
1 change: 1 addition & 0 deletions x/ecocredit/server/basket/invariants.go
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@ func (k Keeper) computeBasketBalances(ctx context.Context) (map[uint64]math.Dec,
if err != nil {
return nil, fmt.Errorf("can't create basket balance iterator, %w", err)
}
defer it.Close()
balances := map[uint64]math.Dec{}
for it.Next() {
b, err := it.Value()
Expand Down
1 change: 1 addition & 0 deletions x/ecocredit/server/core/query_balances.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ func (k Keeper) Balances(ctx context.Context, req *core.QueryBalancesRequest) (*
if err != nil {
return nil, err
}
defer it.Close()

balances := make([]*core.BatchBalanceInfo, 0, 8) // pre-allocate some cap space
for it.Next() {
Expand Down
1 change: 1 addition & 0 deletions x/ecocredit/server/core/query_batches_by_class.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ func (k Keeper) BatchesByClass(ctx context.Context, request *core.QueryBatchesBy
if err != nil {
return nil, err
}
defer it.Close()

batches := make([]*core.BatchInfo, 0, 10)
for it.Next() {
Expand Down
1 change: 1 addition & 0 deletions x/ecocredit/server/core/query_batches_by_issuer.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ func (k Keeper) BatchesByIssuer(ctx context.Context, req *core.QueryBatchesByIss
if err != nil {
return nil, err
}
defer it.Close()

batches := make([]*core.BatchInfo, 0, 8)

Expand Down
1 change: 1 addition & 0 deletions x/ecocredit/server/core/query_class_issuers.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ func (k Keeper) ClassIssuers(ctx context.Context, request *core.QueryClassIssuer
if err != nil {
return nil, err
}
defer it.Close()

issuers := make([]string, 0)
for it.Next() {
Expand Down
1 change: 1 addition & 0 deletions x/ecocredit/server/core/query_classes.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ func (k Keeper) Classes(ctx context.Context, request *core.QueryClassesRequest)
if err != nil {
return nil, err
}
defer it.Close()

classes := make([]*core.ClassInfo, 0)
for it.Next() {
Expand Down
1 change: 1 addition & 0 deletions x/ecocredit/server/core/query_classes_by_admin.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ func (k Keeper) ClassesByAdmin(ctx context.Context, req *core.QueryClassesByAdmi
if err != nil {
return nil, err
}
defer it.Close()

adminString := admin.String()
classes := make([]*core.ClassInfo, 0)
Expand Down
1 change: 1 addition & 0 deletions x/ecocredit/server/core/query_projects.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ func (k Keeper) Projects(ctx context.Context, request *core.QueryProjectsRequest
if err != nil {
return nil, err
}
defer it.Close()

projects := make([]*core.ProjectInfo, 0)
for it.Next() {
Expand Down
1 change: 1 addition & 0 deletions x/ecocredit/server/core/query_projects_by_reference_id.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ func (k Keeper) ProjectsByReferenceId(ctx context.Context, req *core.QueryProjec
if err != nil {
return nil, err
}
defer it.Close()

projects := make([]*core.ProjectInfo, 0)
for it.Next() {
Expand Down
2 changes: 2 additions & 0 deletions x/ecocredit/server/core/update_class_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,7 @@ func TestUpdateClass_Issuers(t *testing.T) {
for it.Next() {
count++
}
it.Close()
assert.Equal(t, len(addrs)+len(newAddrs), count, "expected to get %d address matches, got %d", len(addrs)+len(newAddrs), count)

// remove the original addrs
Expand Down Expand Up @@ -142,6 +143,7 @@ func TestUpdateClass_Issuers(t *testing.T) {
assert.Check(t, !addr.Equals(rmAddr), "%s was supposed to be deleted", rmAddr.String())
}
}
it.Close()
}

func TestUpdateClass_IssuersErrs(t *testing.T) {
Expand Down
3 changes: 3 additions & 0 deletions x/ecocredit/server/marketplace/query_allowed_denoms.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,9 @@ func (k Keeper) AllowedDenoms(ctx context.Context, req *marketplace.QueryAllowed
}

it, err := k.stateStore.AllowedDenomTable().List(ctx, &marketplacev1.AllowedDenomPrimaryKey{}, ormlist.Paginate(pg))
if err != nil {
return nil, err
}
defer it.Close()

allowedDenoms := make([]*marketplace.AllowedDenom, 0)
Expand Down

0 comments on commit cf969fd

Please sign in to comment.