Skip to content

Commit

Permalink
Use a new map instead of deleting entries to avoid memory leak
Browse files Browse the repository at this point in the history
  • Loading branch information
cevatbarisyilmaz committed Nov 6, 2019
1 parent f390680 commit 0bce3be
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion plistener.go
Original file line number Diff line number Diff line change
Expand Up @@ -346,31 +346,35 @@ func (pListener *PListener) cleanup() {
break
}
now := time.Now()
newMap := make(map[[16]byte]*ipRecord)
for ip, record := range pListener.ipRecords {
record.mut.Lock()
if record.blocked || record.privileged {
record.mut.Unlock()
newMap[ip] = record
continue
}
if record.blockedUntil != nil {
if now.After(*record.blockedUntil) {
record.blockedUntil = nil
} else {
record.mut.Unlock()
newMap[ip] = record
continue
}
}
if !record.recentlyActive {
if len(record.activeConns) == 0 {
delete(pListener.ipRecords, ip)
record.mut.Unlock()
continue
}
record.history = []time.Time{}
}
record.recentlyActive = false
newMap[ip] = record
record.mut.Unlock()
}
pListener.ipRecords = newMap
pListener.ipRecordMut.Unlock()
}
}

0 comments on commit 0bce3be

Please sign in to comment.