aboutsummaryrefslogtreecommitdiff
path: root/src/database/sql/sql.go
diff options
context:
space:
mode:
authorDaniel Theophanes <kardianos@gmail.com>2017-12-21 09:31:39 -0800
committerBrad Fitzpatrick <bradfitz@golang.org>2018-01-03 18:18:40 +0000
commit78583a125ae028b4c4ffc2732dfd1cd98855917c (patch)
tree0f242414cbb06f589bc7a88e2f416467729001da /src/database/sql/sql.go
parent15bc0a129ac149ac5130cb06d6bfdbbcc7e24d3c (diff)
downloadgo-78583a125ae028b4c4ffc2732dfd1cd98855917c.tar.xz
database/sql: fix nil pointer use within withLock
During the refactor in 1126d1483f0397648905fcd4590ae45352cabd69 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>
Diffstat (limited to 'src/database/sql/sql.go')
-rw-r--r--src/database/sql/sql.go4
1 files changed, 2 insertions, 2 deletions
diff --git a/src/database/sql/sql.go b/src/database/sql/sql.go
index 9f4fa14534..8f5588ed26 100644
--- a/src/database/sql/sql.go
+++ b/src/database/sql/sql.go
@@ -2055,14 +2055,14 @@ func (tx *Tx) StmtContext(ctx context.Context, stmt *Stmt) *Stmt {
stmt.mu.Unlock()
if si == nil {
+ var ds *driverStmt
withLock(dc, func() {
- var ds *driverStmt
ds, err = stmt.prepareOnConnLocked(ctx, dc)
- si = ds.si
})
if err != nil {
return &Stmt{stickyErr: err}
}
+ si = ds.si
}
parentStmt = stmt
}