From 6347238f10dca088cfd126d8b441ecee63f6134d Mon Sep 17 00:00:00 2001 From: Alfonso Acosta Date: Fri, 27 Jan 2017 13:05:50 +0000 Subject: [PATCH] Review feedback --- probe/endpoint/dns_snooper_linux_amd64.go | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/probe/endpoint/dns_snooper_linux_amd64.go b/probe/endpoint/dns_snooper_linux_amd64.go index e18bf7348..6ebd99b5e 100644 --- a/probe/endpoint/dns_snooper_linux_amd64.go +++ b/probe/endpoint/dns_snooper_linux_amd64.go @@ -15,9 +15,10 @@ import ( ) const ( - bufSize = 8 * 1024 * 1024 // 8MB - maxReverseDNSrecords = 10000 - maxLogsPerDecodingError = 4 + bufSize = 8 * 1024 * 1024 // 8MB + maxReverseDNSrecords = 10000 + maxLogsPerDecodingError = 4 + maxDecodingErrorCardinality = 1000 ) // DNSSnooper is a snopper of DNS queries @@ -209,6 +210,11 @@ func (s *DNSSnooper) run() { // handleDecodeError logs errors up to the maximum allowed count func (s *DNSSnooper) handleDecodingError(err error) { + // prevent potential memory leak + if len(s.decodingErrorCounts) > maxDecodingErrorCardinality { + return + } + str := err.Error() count := s.decodingErrorCounts[str] count++