Skip to content

Commit

Permalink
database/sql: fix memory leaks in Stmt.removeClosedStmtLocked
Browse files Browse the repository at this point in the history
Zero out elements before shrinking the slice to avoid memory leaks.

Fixes golang#66410

Change-Id: I8f64c21455761f7f7c8b6fee0b6450b98f691d91
GitHub-Last-Rev: b15586e
GitHub-Pull-Request: golang#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>
  • Loading branch information
apocelipes authored and bradfitz committed Apr 3, 2024
1 parent 6fcca66 commit 48d7185
Showing 1 changed file with 2 additions and 0 deletions.
2 changes: 2 additions & 0 deletions src/database/sql/sql.go
Original file line number Diff line number Diff line change
Expand Up @@ -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--
}
Expand Down

0 comments on commit 48d7185

Please sign in to comment.