lib/promscrape/discoveryutils: always store just allocated string to sanitized label names cache

This is a follow-up for c06e7a142c
This commit is contained in:
Aliaksandr Valialkin 2022-08-27 00:28:36 +03:00
parent c06e7a142c
commit 30b8d91727
No known key found for this signature in database
GPG Key ID: A72BEC6CD3D0DED1

View File

@ -29,6 +29,11 @@ func SanitizeLabelName(name string) string {
// Make a copy of name in order to limit memory usage to the name length,
// since the name may point to bigger string.
s := string(append([]byte{}, name...))
if sanitizedName == name {
// point sanitizedName to just allocated s, since it may point to name,
// which, in turn, can point to bigger string.
sanitizedName = s
}
sp := &sanitizedName
m.Store(s, sp)
n := atomic.AddUint64(&sanitizedLabelNamesLen, 1)