sqlclosecheck icon indicating copy to clipboard operation
sqlclosecheck copied to clipboard

sqlclosecheck crashes when sql.Stmt is stored in global var

Open TelpeNight opened this issue 1 year ago • 1 comments

sqlclosecheck doesn't work correctly in this case. #20 - a concrete test case.

Maybe this approach of dealing with Stmt is not good, but we have some small go scripts which work in this way. So the crash prevents us to run check on the whole codebase.

The test output:

=== RUN   Test
panic: runtime error: invalid memory address or nil pointer dereference
[signal SIGSEGV: segmentation violation code=0x1 addr=0x8 pc=0x12438f8]

goroutine 349 [running]:
github.com/ryanrolds/sqlclosecheck/pkg/analyzer.getAction({0x1391d78?, 0xc006d63da0?}, {0xc0078d6880?, 0x2, 0x2})
	sqlclosecheck/pkg/analyzer/analyzer.go:250 +0x258
github.com/ryanrolds/sqlclosecheck/pkg/analyzer.checkClosed(0xc007ecd700?, {0xc0078d6880, 0x2, 0x2})
	sqlclosecheck/pkg/analyzer/analyzer.go:185 +0x85
github.com/ryanrolds/sqlclosecheck/pkg/analyzer.run(0xc00867e2d0)
	sqlclosecheck/pkg/analyzer/analyzer.go:77 +0x285
golang.org/x/tools/go/analysis/internal/checker.(*action).execOnce(0xc0086606e0)
	sqlclosecheck/vendor/golang.org/x/tools/go/analysis/internal/checker/checker.go:725 +0x9ec
sync.(*Once).doSlow(0x129d2e9?, 0xc00009e000?)
	/Users/nick/go/go1.20.2/src/sync/once.go:74 +0xc2
sync.(*Once).Do(...)
	/Users/nick/go/go1.20.2/src/sync/once.go:65
golang.org/x/tools/go/analysis/internal/checker.(*action).exec(0xc006053b78?)
	sqlclosecheck/vendor/golang.org/x/tools/go/analysis/internal/checker/checker.go:641 +0x3d
golang.org/x/tools/go/analysis/internal/checker.execAll.func1(0x0?)
	sqlclosecheck/vendor/golang.org/x/tools/go/analysis/internal/checker/checker.go:629 +0x25
created by golang.org/x/tools/go/analysis/internal/checker.execAll
	sqlclosecheck/vendor/golang.org/x/tools/go/analysis/internal/checker/checker.go:635 +0x165


Process finished with the exit code 1

TelpeNight avatar Mar 30 '23 12:03 TelpeNight