From dd85d7ca976719b792c4ddf4698d27aca15d4816 Mon Sep 17 00:00:00 2001 From: Arve Knudsen Date: Mon, 19 Jan 2026 12:14:31 +0100 Subject: [PATCH] tsdb: fix memory leaks in buffer pools (#17879) * tsdb: fix memory leaks in buffer pools Clear reference fields when returning buffers to pools to avoid retaining data after the buffer is reused. Affected pools: - refSeriesPool: clear Labels - histogramsPool: clear H pointer - floatHistogramsPool: clear FH pointer - metadataPool: clear Unit and Help strings Signed-off-by: Arve Knudsen * Clear slices Signed-off-by: Arve Knudsen * Clear metadata buffer Signed-off-by: Arve Knudsen * Remove tests Signed-off-by: Arve Knudsen --------- Signed-off-by: Arve Knudsen --- tsdb/head_append.go | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/tsdb/head_append.go b/tsdb/head_append.go index 6a04fd16d9..539884e74b 100644 --- a/tsdb/head_append.go +++ b/tsdb/head_append.go @@ -214,6 +214,9 @@ func (h *Head) getRefSeriesBuffer() []record.RefSeries { } func (h *Head) putRefSeriesBuffer(b []record.RefSeries) { + for i := range b { // Zero out to avoid retaining label data. + b[i].Labels = labels.EmptyLabels() + } h.refSeriesPool.Put(b[:0]) } @@ -257,6 +260,7 @@ func (h *Head) getHistogramBuffer() []record.RefHistogramSample { } func (h *Head) putHistogramBuffer(b []record.RefHistogramSample) { + clear(b) h.histogramsPool.Put(b[:0]) } @@ -269,6 +273,7 @@ func (h *Head) getFloatHistogramBuffer() []record.RefFloatHistogramSample { } func (h *Head) putFloatHistogramBuffer(b []record.RefFloatHistogramSample) { + clear(b) h.floatHistogramsPool.Put(b[:0]) } @@ -281,6 +286,7 @@ func (h *Head) getMetadataBuffer() []record.RefMetadata { } func (h *Head) putMetadataBuffer(b []record.RefMetadata) { + clear(b) h.metadataPool.Put(b[:0]) }