This is an automated email from the ASF dual-hosted git repository.

chenBright pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/brpc.git


The following commit(s) were added to refs/heads/master by this push:
     new 0b0f7c73e Fix object pool size reporting under ASan (#3739)
0b0f7c73e is described below

commit 0b0f7c73e70c5cf88076884eb615a23cc1bed76e
Author: Bright Chen <[email protected]>
AuthorDate: Sat Nov 14 13:59:13 2026 +0800

    Fix object pool size reporting under ASan (#3739)
---
 src/butil/object_pool_inl.h   |  2 +-
 test/object_pool_unittest.cpp | 23 +++++++++++++++++++++++
 2 files changed, 24 insertions(+), 1 deletion(-)

diff --git a/src/butil/object_pool_inl.h b/src/butil/object_pool_inl.h
index c807b6816..151932130 100644
--- a/src/butil/object_pool_inl.h
+++ b/src/butil/object_pool_inl.h
@@ -380,7 +380,7 @@ public:
                 }
             }
         }
-        info.total_size = info.block_num * info.block_item_num * sizeof(T);
+        info.total_size = info.block_num * info.block_item_num * 
sizeof(BlockItem);
         return info;
     }
 
diff --git a/test/object_pool_unittest.cpp b/test/object_pool_unittest.cpp
index 628203551..b8cd8418f 100644
--- a/test/object_pool_unittest.cpp
+++ b/test/object_pool_unittest.cpp
@@ -138,6 +138,7 @@ void check_block_capacity(size_t expected_capacity) {
     }
 
     clear_objects<T>();
+    EXPECT_EQ(0u, describe_objects<T>().total_size);
     EXPECT_EQ(expected_capacity, describe_objects<T>().block_item_num);
     std::vector<T*> objects;
     for (size_t i = 0; i < expected_capacity; ++i) {
@@ -147,9 +148,11 @@ void check_block_capacity(size_t expected_capacity) {
         objects.push_back(obj);
     }
     EXPECT_EQ(1u, describe_objects<T>().block_num);
+    EXPECT_EQ(sizeof(Block::items), describe_objects<T>().total_size);
     T* next = get_object<T>();
     ASSERT_TRUE(next);
     EXPECT_EQ(2u, describe_objects<T>().block_num);
+    EXPECT_EQ(2 * sizeof(Block::items), describe_objects<T>().total_size);
     EXPECT_EQ(0, return_object(next));
     EXPECT_EQ(next, get_object<T>());
     EXPECT_EQ(0, return_object(next));
@@ -157,7 +160,27 @@ void check_block_capacity(size_t expected_capacity) {
         EXPECT_EQ('x', obj->data[0]);
         EXPECT_EQ(0, return_object(obj));
     }
+    EXPECT_EQ(2 * sizeof(Block::items), describe_objects<T>().total_size);
     clear_objects<T>();
+    EXPECT_EQ(0u, describe_objects<T>().total_size);
+}
+
+TEST_F(ObjectPoolTest, total_size_counts_slot_storage) {
+    clear_objects<char>();
+    EXPECT_EQ(0u, describe_objects<char>().total_size);
+    char* obj = get_object<char>();
+    ASSERT_TRUE(obj);
+    const ObjectPoolInfo info = describe_objects<char>();
+    EXPECT_EQ(1u, info.item_num);
+#ifdef BUTIL_USE_ASAN
+    EXPECT_EQ(2048u, info.total_size);
+#else
+    EXPECT_EQ(256u, info.total_size);
+#endif
+    EXPECT_EQ(0, return_object(obj));
+    EXPECT_EQ(info.total_size, describe_objects<char>().total_size);
+    clear_objects<char>();
+    EXPECT_EQ(0u, describe_objects<char>().total_size);
 }
 
 TEST_F(ObjectPoolTest, block_size_limit_includes_slot_padding) {


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to