github-vet / github-vet/rangeloop-pointer-findings
haorong4/DFS_MapReduce: mp4/introducer/introducer.go; 100 LoC
- Dominant language
- No language data
- Stars
- 0
- Forks
- 0
- PR merge metrics
- PR metrics pending
Description
Found a possible issue in [haorong4/DFS_MapReduce](https://www.github.com/haorong4/DFS_MapReduce) at [mp4/introducer/introducer.go](https://github.com/haorong4/DFS_MapReduce/blob/004443a0706f615dbf5fc2a6d42c961afbdd473c/mp4/introducer/introducer.go#L161-L260)
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.
> range-loop variable filename used in defer or goroutine at line 251
[Click here to see the code in its original context.](https://github.com/haorong4/DFS_MapReduce/blob/004443a0706f615dbf5fc2a6d42c961afbdd473c/mp4/introducer/introducer.go#L161-L260)
Click here to show the 100 line(s) of Go which triggered the analyzer.
```go
for _, filename := range files {
var wg_temp sync.WaitGroup
fileData := make(map[string]string)
if _, ok := RLmap[filename]; !ok {
getFromRemote("get " + filename + " " + filename)
}
file, err := os.Open("files/" + filename)
if err != nil {
log.Fatal(err)
}
defer file.Close()
FReader := bufio.NewReader(file)
outer:
for {
inputStr := ""
for i := 0; i < 10; i++ {
line, _, err := FReader.ReadLine()
if err != nil {
if len(inputStr) == 0 {
break outer
} else {
fmt.Println("bash -c ./files/" + exe)
cmd := exec.Command("bash", "-c", "./files/"+exe)
stdin, err := cmd.StdinPipe()
if err != nil {
log.Fatal(err)
}
stdout, err := cmd.StdoutPipe()
if err != nil {
log.Fatal(err)
}
cmd.Start()
io.WriteString(stdin, inputStr)
stdin.Close()
buffer := make([]byte, 1000)
bytenum, _ := io.ReadFull(stdout, buffer)
buffer = buffer[:bytenum]
KVpairs := bytes.Split(buffer, []byte("\n"))
for _, pair := range KVpairs[:len(KVpairs)-1] {
entries := bytes.Split(pair, []byte(" "))
key := string(entries[0])
value := string(pair)
if _, ok := fileData[key]; ok {
fileData[key] += value + "\n"
} else {
fileData[key] = value + "\n"
}
}
stdout.Close()
cmd.Wait()
}
break outer
} else {
inputStr += string(line)
inputStr += "\n"
}
}
cmd := exec.Command("bash", "-c", "./files/"+exe)
stdin, err := cmd.StdinPipe()
if err != nil {
log.Fatal(err)
}
stdout, err := cmd.StdoutPipe()
if err != nil {
log.Fatal(err)
}
cmd.Start()
io.WriteString(stdin, inputStr)
stdin.Close()
buffer := make([]byte, 1000)
bytenum, _ := io.ReadFull(stdout, buffer)
buffer = buffer[:bytenum]
KVpairs := bytes.Split(buffer, []byte("\n"))
for _, pair := range KVpairs[:len(KVpairs)-1] {
entries := bytes.Split(pair, []byte(" "))
key := string(entries[0])
value := string(pair)
if _, ok := fileData[key]; ok {
fileData[key] += value + "\n"
} else {
fileData[key] = value + "\n"
}
}
stdout.Close()
cmd.Wait()
}
for key, data := range fileData {
channelControl <- true
wg_temp.Add(1)
go func(key_ string, data_ string) {
appendToRemote("append " + filename + " " + prefix + "_" + key_ + " " + data_)
wg_temp.Done()
<-channelControl
}(key, data)
}
wg_temp.Wait()
conn, _ = net.Dial("tcp", master+FILEPORT)
conn.Write([]byte("FileDone\n" + filename + "\n"))
conn.Close()
}
```
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: 004443a0706f615dbf5fc2a6d42c961afbdd473c
Contributor guide
No contributing guide indexed for this repository
Assessment
This issue has not been assessed yet.