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
  • Loading branch information
apocelipes committed Mar 20, 2024
1 parent f94d82b commit 9a61a59
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 9a61a59

Please sign in to comment.