Skip to content

Commit 84d2aad

Browse files
common/async:: Update delete operator in CompletionImpl for improved memory management
Fix UB in CompletionImpl 'operator delete' to eliminate uninitialized memory access Fixes: https://tracker.ceph.com/issues/72478 Signed-off-by: Edwin Rodriguez <[email protected]>
1 parent 7b5fe62 commit 84d2aad

File tree

1 file changed

+11
-2
lines changed

1 file changed

+11
-2
lines changed

src/common/async/completion.h

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -246,8 +246,17 @@ class CompletionImpl final : public Completion<void(Args...), T> {
246246
std::forward<TArgs>(args)...)};
247247
}
248248

249-
static void operator delete(void *p) {
250-
static_cast<CompletionImpl*>(p)->destroy();
249+
// C++20 destroying delete.
250+
// When this overload is selected by `delete ptr`, the compiler does NOT call
251+
// ~CompletionImpl(). We must do the full teardown here. We route through
252+
// destroy() so that:
253+
// - the completion’s custom lifecycle (defer/dispatch/post) is honored,
254+
// - the object’s destructor is invoked, and
255+
// - deallocation is performed using the matching allocator (RebindAlloc2).
256+
// Keep this function noexcept; destroy() is responsible for both destruction
257+
// and allocator-aware deallocation.
258+
static void operator delete(CompletionImpl* ptr, std::destroying_delete_t) noexcept {
259+
ptr->destroy();
251260
}
252261
};
253262

0 commit comments

Comments
 (0)