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 <arve.knudsen@gmail.com>

* Clear slices

Signed-off-by: Arve Knudsen <arve.knudsen@gmail.com>

* Clear metadata buffer

Signed-off-by: Arve Knudsen <arve.knudsen@gmail.com>

* Remove tests

Signed-off-by: Arve Knudsen <arve.knudsen@gmail.com>

---------

Signed-off-by: Arve Knudsen <arve.knudsen@gmail.com>
This commit is contained in:
Arve Knudsen 2026-01-19 12:14:31 +01:00 committed by GitHub
parent c4b0da94db
commit dd85d7ca97
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -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])
}