github-vet / github-vet/rangeloop-pointer-findings

danos/journalbeat: libbeat/template/processor.go; 70 LoC

Open
#5,885 0 comments 0 reactions 0 assignees View on GitHub
fresh medium
Dominant language
No language data
Stars
0
Forks
0
PR merge metrics
PR metrics pending

Description

Found a possible issue in [danos/journalbeat](https://www.github.com/danos/journalbeat) at [libbeat/template/processor.go](https://github.com/danos/journalbeat/blob/bed9a2433561b7f7021374d8e8adce1f9132e5f0/libbeat/template/processor.go#L41-L110)

Below is the message reported by the analyzer for this snippet of code. Beware that the analyzer only reports the first
issue it finds, so please do not limit your consideration to the contents of the below message.

> function call which takes a reference to field at line 104 may start a goroutine

[Click here to see the code in its original context.](https://github.com/danos/journalbeat/blob/bed9a2433561b7f7021374d8e8adce1f9132e5f0/libbeat/template/processor.go#L41-L110)

Click here to show the 70 line(s) of Go which triggered the analyzer.

```go
for _, field := range fields {

if field.Name == "" {
continue
}

field.Path = path
var mapping common.MapStr

switch field.Type {
case "ip":
mapping = p.ip(&field)
case "scaled_float":
mapping = p.scaledFloat(&field)
case "half_float":
mapping = p.halfFloat(&field)
case "integer":
mapping = p.integer(&field)
case "text":
mapping = p.text(&field)
case "", "keyword":
mapping = p.keyword(&field)
case "object":
mapping = p.object(&field)
case "array":
mapping = p.array(&field)
case "alias":
mapping = p.alias(&field)
case "group":
var newPath string
if path == "" {
newPath = field.Name
} else {
newPath = path + "." + field.Name
}
mapping = common.MapStr{}
if field.Dynamic.Value != nil {
mapping["dynamic"] = field.Dynamic.Value
}

// Combine properties with previous field definitions (if any)
properties := common.MapStr{}
key := common.GenerateKey(field.Name) + ".properties"
currentProperties, err := output.GetValue(key)
if err == nil {
var ok bool
properties, ok = currentProperties.(common.MapStr)
if !ok {
// This should never happen
return errors.New(key + " is expected to be a MapStr")
}
}

if err := p.Process(field.Fields, newPath, properties); err != nil {
return err
}
mapping["properties"] = properties
default:
mapping = p.other(&field)
}

switch field.Type {
case "", "keyword", "text":
addToDefaultFields(&field)
}

if len(mapping) > 0 {
output.Put(common.GenerateKey(field.Name), mapping)
}
}

```

Leave a reaction on this issue to contribute to the project by classifying this instance as a **Bug** :-1:, **Mitigated** :+1:, or **Desirable Behavior** :rocket:
See the descriptions of the classifications [here](https://github.com/github-vet/rangeclosure-findings#how-can-i-help) for more information.

commit ID: bed9a2433561b7f7021374d8e8adce1f9132e5f0

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.