1
0
mirror of https://github.com/golang/go synced 2024-09-28 17:14:29 -06:00

database/sql: fix memory leaks in Stmt.removeClosedStmtLocked

Zero out elements before shrinking the slice to avoid memory leaks.

Fixes #66410

Change-Id: I8f64c21455761f7f7c8b6fee0b6450b98f691d91
GitHub-Last-Rev: b15586e801
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>
This commit is contained in:
apocelipes 2024-03-20 05:33:46 +00:00 committed by Emmanuel Odeke
parent 9c94baa7a4
commit e39af550f8

View 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--
}