Skip to content

Commit 18ea9f3

Browse files
Merge pull request ceph#64965 from edwinzrodriguez/ceph-wip-72473
os: Use custom delete operator for raw_combined
2 parents df00e59 + 058b0fb commit 18ea9f3

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
@@ -132,9 +132,16 @@ static ceph::spinlock debug_lock;
132132
new (ptr + datalen) raw_combined(ptr, len, mempool));
133133
}
134134

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

0 commit comments

Comments
 (0)