Skip to content

Commit

Permalink
fix: memory leak in influx parser (influxdata#9787)
Browse files Browse the repository at this point in the history
  • Loading branch information
phemmer authored Oct 7, 2021
1 parent 15753a6 commit 128ed88
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 14 deletions.
14 changes: 7 additions & 7 deletions plugins/parsers/influx/machine.go
Original file line number Diff line number Diff line change
Expand Up @@ -3747,13 +3747,6 @@ func (m *streamMachine) Next() error {
m.machine.finishMetric = false

for {
// Expand the buffer if it is full
if m.machine.pe == len(m.machine.data) {
expanded := make([]byte, 2*len(m.machine.data))
copy(expanded, m.machine.data)
m.machine.data = expanded
}

err := m.machine.exec()
if err != nil {
return err
Expand All @@ -3764,6 +3757,13 @@ func (m *streamMachine) Next() error {
break
}

// Expand the buffer if it is full
if m.machine.pe == len(m.machine.data) {
expanded := make([]byte, 2*len(m.machine.data))
copy(expanded, m.machine.data)
m.machine.data = expanded
}

n, err := m.reader.Read(m.machine.data[m.machine.pe:])
if n == 0 && err == io.EOF {
m.machine.eof = m.machine.pe
Expand Down
14 changes: 7 additions & 7 deletions plugins/parsers/influx/machine.go.rl
Original file line number Diff line number Diff line change
Expand Up @@ -499,13 +499,6 @@ func (m *streamMachine) Next() error {
m.machine.finishMetric = false

for {
// Expand the buffer if it is full
if m.machine.pe == len(m.machine.data) {
expanded := make([]byte, 2 * len(m.machine.data))
copy(expanded, m.machine.data)
m.machine.data = expanded
}

err := m.machine.exec()
if err != nil {
return err
Expand All @@ -516,6 +509,13 @@ func (m *streamMachine) Next() error {
break
}

// Expand the buffer if it is full
if m.machine.pe == len(m.machine.data) {
expanded := make([]byte, 2 * len(m.machine.data))
copy(expanded, m.machine.data)
m.machine.data = expanded
}

n, err := m.reader.Read(m.machine.data[m.machine.pe:])
if n == 0 && err == io.EOF {
m.machine.eof = m.machine.pe
Expand Down

0 comments on commit 128ed88

Please sign in to comment.