Close sql.Rows inline so sqlclosecheck can see it (refs #61)

The ten sqlclosecheck findings were not leaks: every one of these
queries already deferred a close through the package-local CloseRows
helper. sqlclosecheck only recognises a Close call on the rows value
in the function that produced it (directly deferred, or inside a
deferred closure), so a call that hands rows to a helper reads as
unhandled.

Rather than keep a helper the linter cannot see through, drop
CloseRows and defer a closure that calls rows.Close() directly at each
of the eighteen call sites, keeping the existing fatal-on-close-error
behaviour byte for byte. The close still runs exactly once, on
function exit, after the rows have been read.

Fatalf stays; it is still used by the transaction helpers.
This commit is contained in:
2026-08-09 01:48:44 +00:00
parent 047bd7f1c4
commit 7a37a66d88
9 changed files with 126 additions and 27 deletions

View File

@@ -1,7 +1,6 @@
package database
import (
"database/sql"
"fmt"
"os"
)
@@ -11,11 +10,3 @@ func Fatalf(format string, args ...any) {
fmt.Fprintf(os.Stderr, "FATAL: "+format+"\n", args...)
os.Exit(1)
}
// CloseRows closes rows and exits on error
func CloseRows(rows *sql.Rows) {
err := rows.Close()
if err != nil {
Fatalf("failed to close rows: %v", err)
}
}