Skip to content

Commit 1203c31

Browse files
committed
fix: use self_alloc provenance for parent pointers in cursor
1 parent 72c3be4 commit 1203c31

1 file changed

Lines changed: 7 additions & 1 deletion

File tree

src/cursor.rs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -260,7 +260,13 @@ impl NodeData {
260260
let res = NodeData {
261261
_c: Count::new(),
262262
rc: Cell::new(1),
263-
parent: Cell::new(parent.as_ref().map(|it| it.ptr())),
263+
parent: Cell::new(parent.as_ref().map(|it| {
264+
// Use parent's self_alloc pointer which retains full allocation provenance
265+
// from Box::into_raw. Using it.ptr() would give a pointer derived through
266+
// &NodeData references, whose provenance gets frozen under tree borrows,
267+
// causing UB when free() later deallocates through the parent chain.
268+
unsafe { ptr::NonNull::new_unchecked((*it.ptr().as_ptr()).self_alloc) }
269+
})),
264270
index: Cell::new(index),
265271
green,
266272

0 commit comments

Comments
 (0)