Skip to content

Commit 23efb66

Browse files
fix: 🐛 fix memory leak for goroutine
1 parent 93ac47a commit 23efb66

File tree

4 files changed

+10
-3
lines changed

4 files changed

+10
-3
lines changed

core/cache/cache.go

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ package cache
1212

1313
import (
1414
"container/list"
15-
"fmt"
15+
"strings"
1616
"sync"
1717
"time"
1818

@@ -185,7 +185,11 @@ func (c *Cache) GetFastTable(key string) *FastMap {
185185

186186
// Key creates a hash key from a question section.
187187
func Key(q dns.Question) string {
188-
return fmt.Sprintf("%s %d", q.Name, q.Qtype)
188+
var key strings.Builder
189+
key.WriteString(q.Name)
190+
Qtype := []byte{byte(q.Qtype), byte(q.Qtype >> 8)}
191+
key.Write(Qtype)
192+
return key.String()
189193
}
190194

191195
// Hit returns a dns message from the cache. If the message's TTL is expired nil

core/cron/timer.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ func (worker *CacheManager) Handle() {
6161
if !ok {
6262
break
6363
} else {
64-
log.Info(worker.TaskSum)
64+
log.Info("Now timer task: ", worker.TaskSum)
6565
worker.TaskSum--
6666
}
6767
}

core/detector/ping/ping.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import (
1010
"container/list"
1111
"reflect"
1212
"strings"
13+
"time"
1314

1415
"github.com/import-yuefeng/smartDNS/core/cache"
1516
"github.com/import-yuefeng/smartDNS/core/outbound/clients"
@@ -92,6 +93,7 @@ func (data *Pinger) Detect() (fastTable *list.List) {
9293
log.Error(err)
9394
return
9495
}
96+
pinger.Timeout = time.Second * 10
9597
pinger.Count = 1
9698
pinger.Run()
9799
stat := pinger.Statistics()

go.sum

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ github.com/miekg/dns v1.1.15 h1:CSSIDtllwGLMoA6zjdKnaE6Tx6eVUxQ29LUgGetiDCI=
66
github.com/miekg/dns v1.1.15/go.mod h1:W1PPwlIAgtquWBMBEV9nkV9Cazfe8ScdGz/Lj7v3Nrg=
77
github.com/pkg/browser v0.0.0-20180916011732-0a3d74bf9ce4/go.mod h1:4OwLy04Bl9Ef3GJJCoec+30X3LQs/0/m4HFRt/2LUSA=
88
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
9+
github.com/robfig/cron v1.2.0 h1:ZjScXvvxeQ63Dbyxy76Fj3AT3Ut0aKsyd2/tl3DTMuQ=
910
github.com/robfig/cron v1.2.0/go.mod h1:JGuDeoQd7Z6yL4zQhZ3OPEVHB7fL6Ka6skscFHfmt2k=
1011
github.com/sirupsen/logrus v1.4.2 h1:SPIRibHv4MatM3XXNO2BJeFLZwZ2LvZgfQ5+UNI2im4=
1112
github.com/sirupsen/logrus v1.4.2/go.mod h1:tLMulIdttU9McNUspp0xgXVQah82FyeX6MwdIuYE2rE=

0 commit comments

Comments
 (0)