Skip to content

Commit 2aeaa83

Browse files
author
lc
committed
Add missing Wait() and fix memory leak
1 parent a9b6bc6 commit 2aeaa83

1 file changed

Lines changed: 4 additions & 2 deletions

File tree

runner/subjs/runner.go

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ import (
1414
"github.com/PuerkitoBio/goquery"
1515
)
1616

17-
const version = `1.0.0`
17+
const version = `1.0.1`
1818

1919
type SubJS struct {
2020
client *http.Client
@@ -41,6 +41,7 @@ func (s *SubJS) Run() error {
4141
if err != nil {
4242
return fmt.Errorf("Could not open input file: %s", err)
4343
}
44+
defer input.Close()
4445
}
4546

4647
// init channels
@@ -60,10 +61,10 @@ func (s *SubJS) Run() error {
6061
var out sync.WaitGroup
6162
out.Add(1)
6263
go func() {
63-
defer out.Done()
6464
for result := range results {
6565
fmt.Println(result)
6666
}
67+
out.Done()
6768
}()
6869
scan := bufio.NewScanner(input)
6970
for scan.Scan() {
@@ -75,6 +76,7 @@ func (s *SubJS) Run() error {
7576
close(urls)
7677
w.Wait()
7778
close(results)
79+
out.Wait()
7880
return nil
7981
}
8082
func (s *SubJS) fetch(urls <-chan string, results chan string) {

0 commit comments

Comments
 (0)