From 36cdb76113dcc365f071fd14a6a18646b94ff3cf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gustavo=20I=C3=B1iguez=20Goia?= Date: Sun, 21 Mar 2021 21:16:57 +0100 Subject: [PATCH] prevent leaks when reloading domains lists in debug If the log level was debug, when reloading the lists of domains could lead to memory leaks. --- daemon/rule/operator_lists.go | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/daemon/rule/operator_lists.go b/daemon/rule/operator_lists.go index 9f0100ca..d85f68f7 100644 --- a/daemon/rule/operator_lists.go +++ b/daemon/rule/operator_lists.go @@ -86,6 +86,9 @@ Exit: // ClearLists deletes all the entries of a list func (o *Operator) ClearLists() { + o.Lock() + defer o.Unlock() + log.Info("clearing domains lists: %d - %s", len(o.lists), o.Data) for k := range o.lists { delete(o.lists, k) @@ -132,9 +135,7 @@ func (o *Operator) readList(fileName string) (dups uint64) { dups++ continue } - o.Lock() o.lists[host] = fileName - o.Unlock() } raw = nil lines = nil @@ -149,8 +150,8 @@ func (o *Operator) readLists() error { var dups uint64 // this list is particular to this operator and rule o.Lock() + defer o.Unlock() o.lists = make(map[string]string) - o.Unlock() expr := filepath.Join(o.Data, "*.*") fileList, err := filepath.Glob(expr)