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

database/sql: fix memory leaks in Stmt.removeClosedStmtLocked

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

Fixes #66410
This commit is contained in:
apocelipes 2024-03-20 13:43:33 +09:00
parent f94d82b2c0
commit b15586e801

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