diff options
author | Kiril Vladimiroff <kiril@vladimiroff.org> | 2020-02-11 16:12:21 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-02-11 14:12:21 +0000 |
commit | d5dbe546e461261056b5fda1a2ac9fc6d36c69e1 (patch) | |
tree | fc5f950d5c4e51fe2167239b847c4e6d9b01831b /mediaapi | |
parent | d45f869cdd35b07ed9b44445732b27935ca1910d (diff) |
Always defer *sql.Rows.Close and consult with Err (#844)
* Always defer *sql.Rows.Close and consult with Err
database/sql.Rows.Next() makes sure to call Close only after exhausting
result rows which would NOT happen when returning early from a bad Scan.
Close being idempotent makes it a great candidate to get always deferred
regardless of what happens later on the result set.
This change also makes sure call Err() after exhausting Next() and
propagate non-nil results from it as the documentation advises.
Closes #764
Signed-off-by: Kiril Vladimiroff <kiril@vladimiroff.org>
* Override named result parameters in last returns
Signed-off-by: Kiril Vladimiroff <kiril@vladimiroff.org>
* Do the same over new changes that got merged
Signed-off-by: Kiril Vladimiroff <kiril@vladimiroff.org>
Co-authored-by: Neil Alexander <neilalexander@users.noreply.github.com>
Diffstat (limited to 'mediaapi')
-rw-r--r-- | mediaapi/storage/postgres/thumbnail_table.go | 3 |
1 files changed, 2 insertions, 1 deletions
diff --git a/mediaapi/storage/postgres/thumbnail_table.go b/mediaapi/storage/postgres/thumbnail_table.go index 167e3795..127b86bb 100644 --- a/mediaapi/storage/postgres/thumbnail_table.go +++ b/mediaapi/storage/postgres/thumbnail_table.go @@ -144,6 +144,7 @@ func (s *thumbnailStatements) selectThumbnails( if err != nil { return nil, err } + defer rows.Close() // nolint: errcheck var thumbnails []*types.ThumbnailMetadata for rows.Next() { @@ -167,5 +168,5 @@ func (s *thumbnailStatements) selectThumbnails( thumbnails = append(thumbnails, &thumbnailMetadata) } - return thumbnails, err + return thumbnails, rows.Err() } |