BinaryHeap is not exception safe
Closed this issue · 5 comments
bluss commented
BinaryHeap is using zeroed()
and may not be exception safe. I.e. it is in an inconsistent state after being recovered after panic. See issue #25662 and others.
Relevant code is BinaryHeap::sift_up, sift_down_range
cc @cmr
bluss commented
My immediate ideas are one of
- Use PPYP and set vector length to zero temporarily. Panicing in comparison functions will leak all elements in the heap
- Use more swaps
bluss commented
Gankra commented
Long ago I suggested two other strategies:
- A two-pass phase where you do all comparisons first, then once you've found the Final Destination you actually do the swaps (which requires no untrusted code to run).
- A panic guard which on drop puts the "working" element back in the "uninit" location in the array
alexcrichton commented
triage: I-nominated, T-libs
bluss commented
I'm trying gankro's panic guard idea.