Fix memory leak
This commit is contained in:
@@ -668,7 +668,7 @@ struct Metric {
|
|||||||
};
|
};
|
||||||
|
|
||||||
struct AggregateCounter {
|
struct AggregateCounter {
|
||||||
std::vector<Counter::State *> thread_states;
|
std::span<Counter::State *const> thread_states;
|
||||||
Counter::State *global_state;
|
Counter::State *global_state;
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -677,7 +677,7 @@ struct Metric {
|
|||||||
};
|
};
|
||||||
|
|
||||||
struct AggregateHistogram {
|
struct AggregateHistogram {
|
||||||
std::vector<Histogram::State *> thread_states;
|
std::span<Histogram::State *const> thread_states;
|
||||||
Histogram::State *global_state;
|
Histogram::State *global_state;
|
||||||
size_t bucket_count;
|
size_t bucket_count;
|
||||||
std::span<const double> buckets; // For bucket threshold formatting
|
std::span<const double> buckets; // For bucket threshold formatting
|
||||||
@@ -724,26 +724,12 @@ struct Metric {
|
|||||||
new (&aggregate_histogram) AggregateHistogram(ah);
|
new (&aggregate_histogram) AggregateHistogram(ah);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Destructor
|
// Destructor not needed, all instructions are trivially destructible
|
||||||
~RenderInstruction() {
|
static_assert(std::is_trivially_destructible_v<CallCounterCallback>);
|
||||||
switch (type) {
|
static_assert(std::is_trivially_destructible_v<CallGaugeCallback>);
|
||||||
case InstructionType::CALL_COUNTER_CALLBACK:
|
static_assert(std::is_trivially_destructible_v<AggregateCounter>);
|
||||||
counter_callback.~CallCounterCallback();
|
static_assert(std::is_trivially_destructible_v<AggregateGauge>);
|
||||||
break;
|
static_assert(std::is_trivially_destructible_v<AggregateHistogram>);
|
||||||
case InstructionType::CALL_GAUGE_CALLBACK:
|
|
||||||
gauge_callback.~CallGaugeCallback();
|
|
||||||
break;
|
|
||||||
case InstructionType::AGGREGATE_COUNTER:
|
|
||||||
aggregate_counter.~AggregateCounter();
|
|
||||||
break;
|
|
||||||
case InstructionType::AGGREGATE_GAUGE:
|
|
||||||
aggregate_gauge.~AggregateGauge();
|
|
||||||
break;
|
|
||||||
case InstructionType::AGGREGATE_HISTOGRAM:
|
|
||||||
aggregate_histogram.~AggregateHistogram();
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Copy constructor and assignment
|
// Copy constructor and assignment
|
||||||
RenderInstruction(const RenderInstruction &other) : type(other.type) {
|
RenderInstruction(const RenderInstruction &other) : type(other.type) {
|
||||||
@@ -769,9 +755,8 @@ struct Metric {
|
|||||||
|
|
||||||
RenderInstruction &operator=(const RenderInstruction &other) {
|
RenderInstruction &operator=(const RenderInstruction &other) {
|
||||||
if (this != &other) {
|
if (this != &other) {
|
||||||
// Destroy current object
|
// All union members are trivially destructible, so no need to call
|
||||||
this->~RenderInstruction();
|
// destructor. Just reconstruct with new type and data.
|
||||||
// Reconstruct with new type and data
|
|
||||||
type = other.type;
|
type = other.type;
|
||||||
switch (type) {
|
switch (type) {
|
||||||
case InstructionType::CALL_COUNTER_CALLBACK:
|
case InstructionType::CALL_COUNTER_CALLBACK:
|
||||||
|
|||||||
Reference in New Issue
Block a user