Fix final placement new in metric.cpp

This commit is contained in:
2025-09-02 15:31:57 -04:00
parent 7f562f8116
commit d43e6c2be5

View File

@@ -350,13 +350,15 @@ struct Metric {
}
static auto &get_gauge_families() {
using FamilyMap = std::map<
std::string_view, Family<Gauge>::State *, std::less<std::string_view>,
using FamilyMap =
std::map<std::string_view, ArenaAllocator::Ptr<Family<Gauge>::State>,
std::less<std::string_view>,
ArenaStlAllocator<
std::pair<const std::string_view, Family<Gauge>::State *>>>;
std::pair<const std::string_view,
ArenaAllocator::Ptr<Family<Gauge>::State>>>>;
static FamilyMap *gaugeFamilies = new FamilyMap(
ArenaStlAllocator<
std::pair<const std::string_view, Family<Gauge>::State *>>(
ArenaStlAllocator<std::pair<const std::string_view,
ArenaAllocator::Ptr<Family<Gauge>::State>>>(
&get_global_arena()));
return *gaugeFamilies;
}
@@ -901,9 +903,7 @@ Family<Gauge> create_gauge(std::string_view name, std::string_view help) {
if (!familyPtr) {
// NOTE: Family<T>::State instances are never destroyed - this is fine
// because the number of metric families is bounded by application design
familyPtr = new (global_arena.allocate_raw(sizeof(Family<Gauge>::State),
alignof(Family<Gauge>::State)))
Family<Gauge>::State(global_arena);
familyPtr = global_arena.construct<Family<Gauge>::State>(global_arena);
familyPtr->name = name_view;
familyPtr->help = arena_copy_string(help, global_arena);
} else {
@@ -912,7 +912,7 @@ Family<Gauge> create_gauge(std::string_view name, std::string_view help) {
"metric family already registered with different help text", name);
}
Family<Gauge> family;
family.p = familyPtr;
family.p = familyPtr.get();
return family;
}