]> Cypherpunks repositories - gostls13.git/commitdiff
database/sql: fix memory leaks in Stmt.removeClosedStmtLocked
authorapocelipes <seve3r@outlook.com>
Wed, 20 Mar 2024 05:33:46 +0000 (05:33 +0000)
committerEmmanuel Odeke <emmanuel@orijtech.com>
Wed, 20 Mar 2024 14:17:47 +0000 (14:17 +0000)
Zero out elements before shrinking the slice to avoid memory leaks.

Fixes #66410

Change-Id: I8f64c21455761f7f7c8b6fee0b6450b98f691d91
GitHub-Last-Rev: b15586e801199b9674f5bfcb12a848a55f15a80b
GitHub-Pull-Request: golang/go#66419
Reviewed-on: https://go-review.googlesource.com/c/go/+/572956
TryBot-Result: Gopher Robot <gobot@golang.org>
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Reviewed-by: David Chase <drchase@google.com>
Reviewed-by: Keith Randall <khr@google.com>
Reviewed-by: Emmanuel Odeke <emmanuel@orijtech.com>
Run-TryBot: Emmanuel Odeke <emmanuel@orijtech.com>

src/database/sql/sql.go

index b5facdbf2a16ae279962afc0ac4438ce503c01ad..36995a1059bd6db429a04cc7e19c03855647ab80 100644 (file)
@@ -2684,6 +2684,8 @@ func (s *Stmt) removeClosedStmtLocked() {
        for i := 0; i < len(s.css); i++ {
                if s.css[i].dc.dbmuClosed {
                        s.css[i] = s.css[len(s.css)-1]
+                       // Zero out the last element (for GC) before shrinking the slice.
+                       s.css[len(s.css)-1] = connStmt{}
                        s.css = s.css[:len(s.css)-1]
                        i--
                }