Skip to content

Commit

Permalink
sql/parser: fix memory leak of scanned comments
Browse files Browse the repository at this point in the history
This commit fixes a memory leak that cause a session's
`scanner.Scanner`, which is embedded in a `pgwire.conn` via a
`parser.Parser`, to retain previously scanned SQL comments in all parsed
SQL statements. The scanner's slice of comments would continue to grow
as it parsed new SQL strings with comments, as long as the session
remained open. Also, the slice of comments holds references to the bytes
in `pgwire` read buffers, preventing those buffers from being GC'd.

Fixes cockroachdb#127710

Release note: None
  • Loading branch information
mgartner committed Jul 25, 2024
1 parent 9284f8c commit 0186c32
Showing 1 changed file with 1 addition and 0 deletions.
1 change: 1 addition & 0 deletions pkg/sql/scanner/scan.go
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,7 @@ func (s *Scanner) Init(str string) {
// where we reuse a Scanner).
func (s *Scanner) Cleanup() {
s.bytesPrealloc = nil
s.Comments = nil
}

func (s *Scanner) allocBytes(length int) []byte {
Expand Down

0 comments on commit 0186c32

Please sign in to comment.