Skip to content
This repository has been archived by the owner on May 11, 2022. It is now read-only.

Commit

Permalink
update #76: fix resource leak
Browse files Browse the repository at this point in the history
  • Loading branch information
kamilsk committed Dec 9, 2018
1 parent 67f70f4 commit 6f0b6d5
Showing 1 changed file with 6 additions and 4 deletions.
10 changes: 6 additions & 4 deletions pkg/storage/internal/postgres/license.go
Original file line number Diff line number Diff line change
Expand Up @@ -290,6 +290,7 @@ func (scope licenseManager) Employees(token *types.Token, data query.EmployeeLis
if queryErr != nil {
return nil, queryErr
}
defer func() { _ = rows.Close() }()
employees := make([]types.Employee, 0, 4)
for rows.Next() {
var employee types.Employee
Expand All @@ -300,8 +301,8 @@ func (scope licenseManager) Employees(token *types.Token, data query.EmployeeLis
}
employees = append(employees, employee)
}
if rows.Err() != nil {
return nil, errors.Wrapf(rows.Err(),
if loopErr := rows.Err(); loopErr != nil {
return nil, errors.Wrapf(loopErr,
"user %q of account %q with token %q tried to read employees of license %q",
token.UserID, token.User.AccountID, token.ID, license.ID)
}
Expand Down Expand Up @@ -371,6 +372,7 @@ func (scope licenseManager) Workplaces(token *types.Token, data query.WorkplaceL
if queryErr != nil {
return nil, queryErr
}
defer func() { _ = rows.Close() }()
workplaces := make([]types.Workplace, 0, 4)
for rows.Next() {
var workplace types.Workplace
Expand All @@ -382,8 +384,8 @@ func (scope licenseManager) Workplaces(token *types.Token, data query.WorkplaceL
}
workplaces = append(workplaces, workplace)
}
if rows.Err() != nil {
return nil, errors.Wrapf(rows.Err(),
if loopErr := rows.Err(); loopErr != nil {
return nil, errors.Wrapf(loopErr,
"user %q of account %q with token %q tried to read employees of license %q",
token.UserID, token.User.AccountID, token.ID, license.ID)
}
Expand Down

0 comments on commit 6f0b6d5

Please sign in to comment.