From 128ed8849b16239707a9bedd059029792aceac53 Mon Sep 17 00:00:00 2001 From: Patrick Hemmer Date: Thu, 7 Oct 2021 16:35:44 -0400 Subject: [PATCH] fix: memory leak in influx parser (#9787) --- plugins/parsers/influx/machine.go | 14 +++++++------- plugins/parsers/influx/machine.go.rl | 14 +++++++------- 2 files changed, 14 insertions(+), 14 deletions(-) diff --git a/plugins/parsers/influx/machine.go b/plugins/parsers/influx/machine.go index 2649cdb42..4bbf8c079 100644 --- a/plugins/parsers/influx/machine.go +++ b/plugins/parsers/influx/machine.go @@ -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 @@ -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 diff --git a/plugins/parsers/influx/machine.go.rl b/plugins/parsers/influx/machine.go.rl index 29f430786..d6b5d949e 100644 --- a/plugins/parsers/influx/machine.go.rl +++ b/plugins/parsers/influx/machine.go.rl @@ -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 @@ -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