Skip to content

Fix bug / leak in JS function processors #12600

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.next.asciidoc
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ https://github.com/elastic/beats/compare/v7.0.0-alpha2...master[Check the HEAD d
- Add host.os.codename to fields.yml. {pull}12261[12261]
- Fix `@timestamp` being duplicated in events if `@timestamp` is set in a
processor (or by any code utilizing `PutValue()` on a `beat.Event`).
- Fix leak in script processor when using Javascript functions in a processor chain. {pull}12600[12600]

*Auditbeat*

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ func (b *chainBuilder) Add(call goja.FunctionCall) goja.Value {
case *beatProcessor:
b.procs = append(b.procs, v.p)
case func(goja.FunctionCall) goja.Value:
b.procs = append(b.procs, &jsProcessor{fn: v})
b.procs = append(b.procs, newJSProcessor(v))
default:
panic(b.runtime.NewGoError(errors.Errorf("arg0 must be a processor object, but got %T", a0.Export())))
}
Expand Down Expand Up @@ -119,9 +119,12 @@ type jsProcessor struct {
call goja.FunctionCall
}

func newJSProcessor(fn jsFunction) *jsProcessor {
return &jsProcessor{fn: fn, call: goja.FunctionCall{Arguments: make([]goja.Value, 1)}}
}

func (p *jsProcessor) run(event javascript.Event) error {
p.call.Arguments = p.call.Arguments[0:]
p.call.Arguments = append(p.call.Arguments, event.JSObject())
p.call.Arguments[0] = event.JSObject()
p.fn(p.call)
return nil
}
Expand Down