Skip to content

Commit

Permalink
Fix possible segment fault in delete_stats() of MultiDimension. (apac…
Browse files Browse the repository at this point in the history
…he#2237) (apache#2238)

Signed-off-by: Ketor <d.ketor@gmail.com>
  • Loading branch information
ketor authored and Yang Liming committed Oct 31, 2023
1 parent a41c7c3 commit 2ebf984
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 0 deletions.
1 change: 1 addition & 0 deletions src/bvar/multi_dimension_inl.h
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,7 @@ void MultiDimension<T>::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();
Expand Down
2 changes: 2 additions & 0 deletions test/bvar_multi_dimension_unittest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<int> *adder5 = my_madder.get_stats(labels_value1);
ASSERT_TRUE(adder5);
}

TEST_F(MultiDimensionTest, get_description) {
Expand Down

0 comments on commit 2ebf984

Please sign in to comment.