From cc74bc138e5ff8694de4af6a231a073914a0f943 Mon Sep 17 00:00:00 2001 From: jonbodner Date: Thu, 12 Feb 2026 14:09:01 -0500 Subject: [PATCH] Fix resource leak by deferring rows.Close() in handleMapping. The previous code called rows.Close() at the end of the function body, which was skipped on early error returns in the slice loop and would also be skipped on panics during row mapping. Co-Authored-By: Claude Opus 4.6 --- runner.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/runner.go b/runner.go index 36cdf9f..5b3c70d 100644 --- a/runner.go +++ b/runner.go @@ -308,6 +308,7 @@ func makeQuerierReturnVals(ctx context.Context, funcType reflect.Type, builder m } func handleMapping(ctx context.Context, sType reflect.Type, rows *sql.Rows, builder mapper.Builder) (interface{}, error) { + defer rows.Close() var val interface{} var err error if sType.Kind() == reflect.Slice { @@ -327,7 +328,6 @@ func handleMapping(ctx context.Context, sType reflect.Type, rows *sql.Rows, buil } else { val, err = mapRows(ctx, rows, builder) } - rows.Close() return val, err }