Skip to content

Commit 058b0fb

Browse files
os: Improve custom delete operator for raw_combined to ensure proper memory cleanup
Fix UB in raw_combined 'operator delete' to eliminate uninitialized memory access Fixes: https://tracker.ceph.com/issues/72473 Signed-off-by: Edwin Rodriguez <[email protected]>
1 parent bafdbd6 commit 058b0fb

File tree

1 file changed

+10
-3
lines changed

1 file changed

+10
-3
lines changed

src/common/buffer.cc

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -131,9 +131,16 @@ static ceph::spinlock debug_lock;
131131
new (ptr + datalen) raw_combined(ptr, len, mempool));
132132
}
133133

134-
static void operator delete(void *ptr) {
135-
raw_combined *raw = (raw_combined *)ptr;
136-
aligned_free((void *)raw->data);
134+
// Custom delete operator that properly handles cleanup of a combined allocation
135+
// where the object is placed after its data buffer. The operator must:
136+
// 1. Save the data pointer before the object is destroyed
137+
// 2. Explicitly call the destructor to clean up the object's members
138+
// 3. Free the entire combined allocation through the data pointer
139+
// Uses std::destroying_delete_t to prevent automatic destructor call after delete
140+
static void operator delete(raw_combined *raw, std::destroying_delete_t) {
141+
char * dataptr = raw->data;
142+
raw->~raw_combined();
143+
aligned_free(dataptr);
137144
}
138145
};
139146

0 commit comments

Comments
 (0)