From 1fcb69d3a913dec9b53f148acab45b1f621faa24 Mon Sep 17 00:00:00 2001
From: Simon Zolin <s.zolin@adguard.com>
Date: Fri, 7 Jun 2019 11:37:55 +0300
Subject: [PATCH] - clients: fix race introduced by commit 07db927; update tech
 doc

---
 AGHTechDoc.md | 2 +-
 clients.go    | 8 ++++----
 dns.go        | 2 +-
 3 files changed, 6 insertions(+), 6 deletions(-)

diff --git a/AGHTechDoc.md b/AGHTechDoc.md
index 48974e2b..e4462ad9 100644
--- a/AGHTechDoc.md
+++ b/AGHTechDoc.md
@@ -526,7 +526,7 @@ Notes:
 
 * If `use_global_settings` is true, then DNS responses for this client are processed and filtered using global settings.
 
-* If `use_global_settings` is false, then the client-specific settings are used to override (disable) global settings.  For example, if global setting `parental_enabled` is true, then per-client setting `parental_enabled:false` can disable Parental Control for this specific client.
+* If `use_global_settings` is false, then the client-specific settings are used to override (enable or disable) global settings.
 
 
 ### Get list of clients
diff --git a/clients.go b/clients.go
index 3974cbe7..88143737 100644
--- a/clients.go
+++ b/clients.go
@@ -89,13 +89,13 @@ func clientExists(ip string) bool {
 }
 
 // Search for a client by IP
-func clientFind(ip string) (*Client, bool) {
+func clientFind(ip string) (Client, bool) {
 	clients.lock.Lock()
 	defer clients.lock.Unlock()
 
 	c, ok := clients.ipIndex[ip]
 	if ok {
-		return c, true
+		return *c, true
 	}
 
 	for _, c = range clients.list {
@@ -109,12 +109,12 @@ func clientFind(ip string) (*Client, bool) {
 				continue
 			}
 			if ip == ipAddr.String() {
-				return c, true
+				return *c, true
 			}
 		}
 	}
 
-	return nil, false
+	return Client{}, false
 }
 
 // Check if Client object's fields are correct
diff --git a/dns.go b/dns.go
index cc3840fc..60f7c4e8 100644
--- a/dns.go
+++ b/dns.go
@@ -216,7 +216,7 @@ func generateServerConfig() dnsforward.ServerConfig {
 // If a client has his own settings, apply them
 func applyClientSettings(clientAddr string, setts *dnsfilter.RequestFilteringSettings) {
 	c, ok := clientFind(clientAddr)
-	if !ok || c == nil || !c.UseOwnSettings {
+	if !ok || !c.UseOwnSettings {
 		return
 	}