]> Cypherpunks repositories - gostls13.git/commitdiff
database/sql: fix nil pointer use within withLock
authorDaniel Theophanes <kardianos@gmail.com>
Thu, 21 Dec 2017 17:31:39 +0000 (09:31 -0800)
committerBrad Fitzpatrick <bradfitz@golang.org>
Wed, 3 Jan 2018 18:18:40 +0000 (18:18 +0000)
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>
src/database/sql/sql.go

index 9f4fa14534dac00866ef73ffc2a2e2d8676631c4..8f5588ed2680886be6766e68d0feb8b77e5d9e29 100644 (file)
@@ -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
        }