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

garo/logs2kafka: main.go; 44 LoC

Open
#15,260 0 comments 0 reactions 0 assignees View on GitHub
fresh small
Dominant language
No language data
Stars
0
Forks
0
PR merge metrics
PR metrics pending

Description

Found a possible issue in [garo/logs2kafka](https://www.github.com/garo/logs2kafka) at [main.go](https://github.com/garo/logs2kafka/blob/cb3a570f6a929d3ff16e7b6267e68f000801526c/main.go#L273-L316)

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.

> reference to message was used in a composite literal at line 277

[Click here to see the code in its original context.](https://github.com/garo/logs2kafka/blob/cb3a570f6a929d3ff16e7b6267e68f000801526c/main.go#L273-L316)

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

```go
for message := range syslog.Messages {
if c.GlobalBool("debug") {
fmt.Printf("Got message: %+v\n", message)
}
EnsureMessageFormat(serverInfo, &message)
SendStatsdMetricsFromMessage(statsd, &message)

if message.Topic == "" {
message.Topic = default_topic
}
message.Topic = topic_prefix + "." + message.Topic

if loggers != nil {

filename := file_logs_path + "/" + message.Topic + ".log"
if c.GlobalBool("debug") {
fmt.Printf("Going to write message to file %s\n", filename)
}

var logger *lumberjack.Logger = nil

logger, ok := loggers[message.Topic]
if !ok {
if c.GlobalBool("debug") {
fmt.Printf("Creating new logger for topic %s\n", message.Topic)
}

logger = &lumberjack.Logger{
Filename: filename,
MaxSize: 100, // megabytes
MaxBackups: 3,
}

loggers[message.Topic] = logger

}
logger.Write([]byte(message.Container.String() + "\n"))
}

if !c.GlobalBool("disable-kafka") {
kafka.Produce(message)
}

}

```

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: cb3a570f6a929d3ff16e7b6267e68f000801526c

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.