Skip to content

Commit 78583a1

Browse files
kardianosbradfitz
authored andcommitted
database/sql: fix nil pointer use within withLock
During the refactor in 1126d14 I introduced a logical error within one withLock function that used the result of the call before checking for the error. Change the order so that the error is checked before the result is used. None of the other withLock uses have similar issues. Fixes #23208 Change-Id: I6c5dcf262e36bad4369c850f1e0131066360a82e Reviewed-on: https://go-review.googlesource.com/85175 Run-TryBot: Daniel Theophanes <kardianos@gmail.com> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Caleb Spare <cespare@gmail.com> Reviewed-by: Ian Lance Taylor <iant@golang.org>
1 parent 15bc0a1 commit 78583a1

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

src/database/sql/sql.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2055,14 +2055,14 @@ func (tx *Tx) StmtContext(ctx context.Context, stmt *Stmt) *Stmt {
20552055
stmt.mu.Unlock()
20562056

20572057
if si == nil {
2058+
var ds *driverStmt
20582059
withLock(dc, func() {
2059-
var ds *driverStmt
20602060
ds, err = stmt.prepareOnConnLocked(ctx, dc)
2061-
si = ds.si
20622061
})
20632062
if err != nil {
20642063
return &Stmt{stickyErr: err}
20652064
}
2065+
si = ds.si
20662066
}
20672067
parentStmt = stmt
20682068
}

0 commit comments

Comments
 (0)