Просмотр исходного кода

util/clientmetric: fix regression causing Metric.v to be uninitialised

m.v was uninitialised when Tailscale built with ts_omit_logtail
Fixes #17918

Signed-off-by: Avery Palmer <[email protected]>
Avery Palmer 3 месяцев назад
Родитель
Сommit
8aa46a3956
1 измененных файлов с 8 добавлено и 5 удалено
  1. 8 5
      util/clientmetric/clientmetric.go

+ 8 - 5
util/clientmetric/clientmetric.go

@@ -133,15 +133,18 @@ func (m *Metric) Publish() {
 	metrics[m.name] = m
 	sortedDirty = true
 
+	if m.f == nil {
+		if len(valFreeList) == 0 {
+			valFreeList = make([]int64, 256)
+		}
+		m.v = &valFreeList[0]
+		valFreeList = valFreeList[1:]
+	}
+
 	if buildfeatures.HasLogTail {
 		if m.f != nil {
 			lastLogVal = append(lastLogVal, scanEntry{f: m.f})
 		} else {
-			if len(valFreeList) == 0 {
-				valFreeList = make([]int64, 256)
-			}
-			m.v = &valFreeList[0]
-			valFreeList = valFreeList[1:]
 			lastLogVal = append(lastLogVal, scanEntry{v: m.v})
 		}
 	}