From db3de7aacff3b67d4ee697814bffe0c8428fd5c9 Mon Sep 17 00:00:00 2001 From: Matt Reiferson Date: Wed, 21 Jun 2017 09:44:38 -0700 Subject: [PATCH] nsqd: fix nil pointer when memstats enabled --- nsqd/http.go | 4 ++-- nsqd/stats.go | 4 ++-- nsqd/statsd.go | 2 +- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/nsqd/http.go b/nsqd/http.go index ddbfc1da6..0323fa79e 100644 --- a/nsqd/http.go +++ b/nsqd/http.go @@ -506,11 +506,11 @@ func (s *httpServer) doStats(w http.ResponseWriter, req *http.Request, ps httpro Health string `json:"health"` StartTime int64 `json:"start_time"` Topics []TopicStats `json:"topics"` - Memory *memStats `json:"memory"` + Memory memStats `json:"memory"` }{version.Binary, health, startTime.Unix(), stats, ms}, nil } -func (s *httpServer) printStats(stats []TopicStats, ms *memStats, health string, startTime time.Time, uptime time.Duration) []byte { +func (s *httpServer) printStats(stats []TopicStats, ms memStats, health string, startTime time.Time, uptime time.Duration) []byte { var buf bytes.Buffer w := &buf now := time.Now() diff --git a/nsqd/stats.go b/nsqd/stats.go index 6f732fa82..53dd18fa4 100644 --- a/nsqd/stats.go +++ b/nsqd/stats.go @@ -157,7 +157,7 @@ type memStats struct { GCTotalRuns uint32 `json:"gc_total_runs"` } -func getMemStats() *memStats { +func getMemStats() memStats { var ms runtime.MemStats runtime.ReadMemStats(&ms) @@ -170,7 +170,7 @@ func getMemStats() *memStats { copy(gcPauses, ms.PauseNs[:length]) sort.Sort(gcPauses) - return &memStats{ + return memStats{ ms.HeapObjects, ms.HeapIdle, ms.HeapInuse, diff --git a/nsqd/statsd.go b/nsqd/statsd.go index 43eca5b76..f532221be 100644 --- a/nsqd/statsd.go +++ b/nsqd/statsd.go @@ -23,7 +23,7 @@ func (s Uint64Slice) Less(i, j int) bool { } func (n *NSQD) statsdLoop() { - var lastMemStats *memStats + var lastMemStats memStats var lastStats []TopicStats ticker := time.NewTicker(n.getOpts().StatsdInterval) for {