Skip to content

Commit

Permalink
Auto merge of #132597 - lukas-code:btree-plug-leak, r=jhpratt
Browse files Browse the repository at this point in the history
btree: don't leak value if destructor of key panics

This PR fixes a regression from rust-lang/rust#84904.

The `BTreeMap` already attempts to handle panicking destructors of the key-value pairs by continuing to execute the remaining destructors after one destructor panicked. However, after #84904 the destructor of a value in a key-value pair gets skipped if the destructor of the key panics, only continuing with the next key-value pair. This PR reverts to the behavior before #84904 to also drop the corresponding value if the destructor of a key panics.

This avoids potential memory leaks and can fix the soundness of programs that rely on the destructors being executed (even though this should not be relied upon, because the std collections currently do not guarantee that the remaining elements are dropped after a panic in a destructor).

cc `@Amanieu` because you had opinions on panicking destructors
  • Loading branch information
bors committed Nov 24, 2024
2 parents 8a40fd0 + 041af8e commit 2926313
Showing 0 changed files with 0 additions and 0 deletions.

0 comments on commit 2926313

Please sign in to comment.