Skip to content

Commit da8f614

Browse files
committed
common: fix backtrace leak in __ceph_abort and friends
Previously, in __ceph_abort and related abort handlers, we allocated ClibBackTrace instances using raw pointers without proper cleanup. Since these handlers terminate execution, the leaks didn't affect production systems but were correctly flagged by ASan during testing: ``` Direct leak of 288 byte(s) in 1 object(s) allocated from: #0 0x55aefe8cb65d in operator new(unsigned long) (/home/jenkins-build/build/workspace/ceph-pull-requests/build/bin/unittest_ceph_assert+0x1f465d) (BuildId: a4faeddac80b0d81062bd53ede3388c0c10680bc) ceph#1 0x7f3b84da988d in ceph::__ceph_assertf_fail(char const*, char const*, int, char const*, char const*, ...) /home/jenkins-build/build/workspace/ceph-pull-requests/src/common/assert.cc:157:21 ceph#2 0x55aefe8cf04b in supressed_assertf_line22() /home/jenkins-build/build/workspace/ceph-pull-requests/src/test/ceph_assert.cc:22:3 ceph#3 0x55aefe8ce4e6 in CephAssertDeathTest_ceph_assert_supresssions_Test::TestBody() /home/jenkins-build/build/workspace/ceph-pull-requests/src/test/ceph_assert.cc:31:3 ceph#4 0x55aefe99135d in void testing::internal::HandleSehExceptionsInMethodIfSupported<testing::Test, void>(testing::Test*, void (testing::Test::*)(), char const*) /home/jenkins-build/build/workspace/ceph-pull-requests/src/googletest/googletest/src/gtest.cc:2653:10 ceph#5 0x55aefe94f015 in void testing::internal::HandleExceptionsInMethodIfSupported<testing::Test, void>(testing::Test*, void (testing::Test::*)(), char const*) /home/jenkins-build/build/workspace/ceph-pull-requests/src/googletest/googletest/src/gtest.cc:2689:14 ... ``` This commit resolves the issue by using std::unique_ptr to manage the lifecycle of backtrace objects, ensuring proper cleanup even in non-returning functions. While these leaks had no practical impact in production (as the process terminates anyway), fixing them improves code quality and eliminates false positives in memory analysis tools. Signed-off-by: Kefu Chai <[email protected]>
1 parent b71625d commit da8f614

File tree

1 file changed

+3
-3
lines changed

1 file changed

+3
-3
lines changed

src/common/assert.cc

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -154,7 +154,7 @@ namespace ceph {
154154
ceph_pthread_getname(g_assert_thread_name, sizeof(g_assert_thread_name));
155155

156156
BufAppender ba(g_assert_msg, sizeof(g_assert_msg));
157-
BackTrace *bt = new ClibBackTrace(1);
157+
auto bt = std::make_unique<ClibBackTrace>(1);
158158
ba.printf("%s: In function '%s' thread %llx time %s\n"
159159
"%s: %d: FAILED ceph_assert(%s)\n",
160160
file, func, (unsigned long long)pthread_self(), tss.str().c_str(),
@@ -212,7 +212,7 @@ namespace ceph {
212212
g_assert_thread = (unsigned long long)pthread_self();
213213
ceph_pthread_getname(g_assert_thread_name, sizeof(g_assert_thread_name));
214214

215-
BackTrace *bt = new ClibBackTrace(1);
215+
auto bt = std::make_unique<ClibBackTrace>(1);
216216
snprintf(g_assert_msg, sizeof(g_assert_msg),
217217
"%s: In function '%s' thread %llx time %s\n"
218218
"%s: %d: ceph_abort_msg(\"%s\")\n", file, func,
@@ -254,7 +254,7 @@ namespace ceph {
254254
ceph_pthread_getname(g_assert_thread_name, sizeof(g_assert_thread_name));
255255

256256
BufAppender ba(g_assert_msg, sizeof(g_assert_msg));
257-
BackTrace *bt = new ClibBackTrace(1);
257+
auto bt = std::make_unique<ClibBackTrace>(1);
258258
ba.printf("%s: In function '%s' thread %llx time %s\n"
259259
"%s: %d: abort()\n",
260260
file, func, (unsigned long long)pthread_self(), tss.str().c_str(),

0 commit comments

Comments
 (0)