From 6d13c072efff60fb7245fff41a5089a89ec30b86 Mon Sep 17 00:00:00 2001 From: Zhang Yifan Date: Thu, 18 Feb 2021 17:30:05 +0800 Subject: [PATCH] fix(perf_counter_wrapper): avoid using invalid perf_counters::instance() to remove counter (#750) --- include/dsn/perf_counter/perf_counter_wrapper.h | 3 ++- src/perf_counter/perf_counters.cpp | 1 + 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/include/dsn/perf_counter/perf_counter_wrapper.h b/include/dsn/perf_counter/perf_counter_wrapper.h index 51ef5a08b6..e834995887 100644 --- a/include/dsn/perf_counter/perf_counter_wrapper.h +++ b/include/dsn/perf_counter/perf_counter_wrapper.h @@ -63,7 +63,7 @@ class perf_counter_wrapper perf_counter_wrapper &operator=(perf_counter_wrapper &other) = delete; perf_counter_wrapper &operator=(perf_counter_wrapper &&other) = delete; - ~perf_counter_wrapper() { clear(); } + ~perf_counter_wrapper() {} // clear the real perf-counter object. // call this function if you want free the counter before the wrapper's destructor is called @@ -103,6 +103,7 @@ class perf_counter_wrapper dsn::perf_counter *get() const { return _counter; } dsn::perf_counter *operator->() const { return _counter; } + private: // use raw pointer to make the class object small, so it can be accessed quickly dsn::perf_counter *_counter; diff --git a/src/perf_counter/perf_counters.cpp b/src/perf_counter/perf_counters.cpp index ef89a84267..732cfd4b01 100644 --- a/src/perf_counter/perf_counters.cpp +++ b/src/perf_counter/perf_counters.cpp @@ -91,6 +91,7 @@ perf_counters::perf_counters() perf_counters::~perf_counters() { + _counters.clear(); UNREGISTER_VALID_HANDLER(_perf_counters_cmd); UNREGISTER_VALID_HANDLER(_perf_counters_by_substr_cmd); UNREGISTER_VALID_HANDLER(_perf_counters_by_prefix_cmd);