From 2ebf9841ba9a13205c234ddd9a6ff20c44136420 Mon Sep 17 00:00:00 2001 From: Ketor Date: Mon, 8 May 2023 09:47:55 +0800 Subject: [PATCH] Fix possible segment fault in delete_stats() of MultiDimension. (#2237) (#2238) Signed-off-by: Ketor --- src/bvar/multi_dimension_inl.h | 1 + test/bvar_multi_dimension_unittest.cpp | 2 ++ 2 files changed, 3 insertions(+) diff --git a/src/bvar/multi_dimension_inl.h b/src/bvar/multi_dimension_inl.h index 9e282dfa4a..0ab960fe72 100644 --- a/src/bvar/multi_dimension_inl.h +++ b/src/bvar/multi_dimension_inl.h @@ -118,6 +118,7 @@ void MultiDimension::delete_stats() { // then traversal tmp_map and delete bvar object, // which can prevent the bvar object from being deleted twice. MetricMap tmp_map; + CHECK_EQ(0, tmp_map.init(8192, 80)); auto clear_fn = [&tmp_map](MetricMap& map) { if (!tmp_map.empty()) { tmp_map.clear(); diff --git a/test/bvar_multi_dimension_unittest.cpp b/test/bvar_multi_dimension_unittest.cpp index b30f8245d7..ebc048b1de 100644 --- a/test/bvar_multi_dimension_unittest.cpp +++ b/test/bvar_multi_dimension_unittest.cpp @@ -355,6 +355,8 @@ TEST_F(MultiDimensionTest, stats) { ASSERT_FALSE(my_madder.has_stats(labels_value2)); ASSERT_FALSE(my_madder.has_stats(labels_value3)); ASSERT_FALSE(my_madder.has_stats(labels_value4)); + bvar::Adder *adder5 = my_madder.get_stats(labels_value1); + ASSERT_TRUE(adder5); } TEST_F(MultiDimensionTest, get_description) {