Skip to content

Commit b594a77

Browse files
authored
Fixed stacked borrows violation in dealloc (fixes #247) (#248)
* Fixed stacked borrows violation in `dealloc` (fixes #247) * Added regression test
1 parent 231403a commit b594a77

File tree

2 files changed

+12
-0
lines changed

2 files changed

+12
-0
lines changed

src/lib.rs

+1
Original file line numberDiff line numberDiff line change
@@ -1705,6 +1705,7 @@ impl Bump {
17051705
// If the pointer is the last allocation we made, we can reuse the bytes,
17061706
// otherwise they are simply leaked -- at least until somebody calls reset().
17071707
if self.is_last_allocation(ptr) {
1708+
let ptr = self.current_chunk_footer.get().as_ref().ptr.get();
17081709
let ptr = NonNull::new_unchecked(ptr.as_ptr().add(layout.size()));
17091710
self.current_chunk_footer.get().as_ref().ptr.set(ptr);
17101711
}

tests/all/tests.rs

+11
Original file line numberDiff line numberDiff line change
@@ -209,3 +209,14 @@ fn test_chunk_capacity() {
209209
b.alloc(true);
210210
assert!(b.chunk_capacity() < orig_capacity);
211211
}
212+
213+
#[test]
214+
#[cfg(feature = "allocator_api")]
215+
fn miri_stacked_borrows_issue_247() {
216+
let bump = bumpalo::Bump::new();
217+
218+
let a = Box::into_raw(Box::new_in(1u8, &bump));
219+
drop(unsafe { Box::from_raw_in(a, &bump) });
220+
221+
let _b = Box::new_in(2u16, &bump);
222+
}

0 commit comments

Comments
 (0)