Skip to content

Commit 25c6962

Browse files
committed
Manually drop records if Sorter is dropped early (e.g. in case of error)
1 parent 4501c41 commit 25c6962

File tree

1 file changed

+12
-0
lines changed

1 file changed

+12
-0
lines changed

core/vdbe/sorter.rs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -408,6 +408,18 @@ impl Sorter {
408408
}
409409
}
410410

411+
impl Drop for Sorter {
412+
fn drop(&mut self) {
413+
// Drop all arena-allocated records to free their inner heap allocations
414+
// (Vec, ImmutableRecord payload, etc.) before the arena memory is released.
415+
// Bumpalo doesn't run destructors, so we must do this manually.
416+
for ptr in self.records.drain(..) {
417+
// SAFETY: All pointers are valid (arena not yet dropped).
418+
unsafe { std::ptr::drop_in_place(ptr.as_ptr()) };
419+
}
420+
}
421+
}
422+
411423
#[derive(Debug, Clone, Copy)]
412424
enum NextState {
413425
Start,

0 commit comments

Comments
 (0)