Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

btree: don't leak value if destructor of key panics #132597

Merged
merged 1 commit into from
Nov 24, 2024

Conversation

lukas-code
Copy link
Member

This PR fixes a regression from #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

@rustbot
Copy link
Collaborator

rustbot commented Nov 4, 2024

r? @jhpratt

rustbot has assigned @jhpratt.
They will have a look at your PR within the next two weeks and either review your PR or reassign to another reviewer.

Use r? to explicitly pick a reviewer

@rustbot rustbot added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. T-libs Relevant to the library team, which will review and decide on the PR/issue. labels Nov 4, 2024
@jhpratt
Copy link
Member

jhpratt commented Nov 22, 2024

@bors r+

@bors
Copy link
Contributor

bors commented Nov 22, 2024

📌 Commit e32a118 has been approved by jhpratt

It is now in the queue for this repository.

@bors bors added S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Nov 22, 2024
compiler-errors added a commit to compiler-errors/rust that referenced this pull request Nov 22, 2024
btree: don't leak value if destructor of key panics

This PR fixes a regression from rust-lang#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 rust-lang#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 rust-lang#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
bors added a commit to rust-lang-ci/rust that referenced this pull request Nov 23, 2024
…mpiler-errors

Rollup of 8 pull requests

Successful merges:

 - rust-lang#131505 (use `confstr(_CS_DARWIN_USER_TEMP_DIR, ...)` as a `TMPDIR` fallback on Darwin)
 - rust-lang#131859 (Update TRPL to add new Chapter 17: Async and Await)
 - rust-lang#132090 (Stop being so bail-y in candidate assembly)
 - rust-lang#132597 (btree: don't leak value if destructor of key panics)
 - rust-lang#132911 (Pretty print async fn sugar in opaques and trait bounds)
 - rust-lang#133159 (Don't allow `-Zunstable-options` to take a value )
 - rust-lang#133247 (Reduce integer `Display` implementation size)
 - rust-lang#133286 (Re-delay a resolve `bug` related to `Self`-ctor in patterns)

Failed merges:

 - rust-lang#133215 (Fix missing submodule in `./x vendor`)

r? `@ghost`
`@rustbot` modify labels: rollup
@compiler-errors
Copy link
Member

Failed in a rollup: #133350 (comment)

@bors r-

@bors bors added S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. and removed S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. labels Nov 23, 2024
@lukas-code lukas-code closed this Nov 23, 2024
@lukas-code lukas-code reopened this Nov 23, 2024
@lukas-code
Copy link
Member Author

Looks like the failure was actually #133247, so

@bors r=jhpratt

@bors
Copy link
Contributor

bors commented Nov 23, 2024

📌 Commit e32a118 has been approved by jhpratt

It is now in the queue for this repository.

@bors bors added S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. and removed S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. labels Nov 23, 2024
@bors
Copy link
Contributor

bors commented Nov 24, 2024

⌛ Testing commit e32a118 with merge 124eb96...

@bors
Copy link
Contributor

bors commented Nov 24, 2024

☀️ Test successful - checks-actions
Approved by: jhpratt
Pushing 124eb96 to master...

@bors bors added the merged-by-bors This PR was explicitly merged by bors. label Nov 24, 2024
@bors bors merged commit 124eb96 into rust-lang:master Nov 24, 2024
13 checks passed
@rustbot rustbot added this to the 1.85.0 milestone Nov 24, 2024
@rust-timer
Copy link
Collaborator

Finished benchmarking commit (124eb96): comparison URL.

Overall result: ❌ regressions - no action needed

@rustbot label: -perf-regression

Instruction count

This is the most reliable metric that we have; it was used to determine the overall result at the top of this comment. However, even this metric can sometimes exhibit noise.

mean range count
Regressions ❌
(primary)
0.3% [0.2%, 0.5%] 2
Regressions ❌
(secondary)
1.4% [1.4%, 1.4%] 1
Improvements ✅
(primary)
- - 0
Improvements ✅
(secondary)
- - 0
All ❌✅ (primary) 0.3% [0.2%, 0.5%] 2

Max RSS (memory usage)

Results (primary -2.8%)

This is a less reliable metric that may be of interest but was not used to determine the overall result at the top of this comment.

mean range count
Regressions ❌
(primary)
3.2% [3.2%, 3.2%] 1
Regressions ❌
(secondary)
- - 0
Improvements ✅
(primary)
-5.7% [-6.8%, -4.7%] 2
Improvements ✅
(secondary)
- - 0
All ❌✅ (primary) -2.8% [-6.8%, 3.2%] 3

Cycles

Results (primary -3.3%)

This is a less reliable metric that may be of interest but was not used to determine the overall result at the top of this comment.

mean range count
Regressions ❌
(primary)
- - 0
Regressions ❌
(secondary)
- - 0
Improvements ✅
(primary)
-3.3% [-3.3%, -3.3%] 1
Improvements ✅
(secondary)
- - 0
All ❌✅ (primary) -3.3% [-3.3%, -3.3%] 1

Binary size

Results (primary 0.0%)

This is a less reliable metric that may be of interest but was not used to determine the overall result at the top of this comment.

mean range count
Regressions ❌
(primary)
0.1% [0.0%, 0.2%] 21
Regressions ❌
(secondary)
- - 0
Improvements ✅
(primary)
-0.0% [-0.0%, -0.0%] 1
Improvements ✅
(secondary)
- - 0
All ❌✅ (primary) 0.0% [-0.0%, 0.2%] 22

Bootstrap: 797.356s -> 796.612s (-0.09%)
Artifact size: 336.34 MiB -> 336.26 MiB (-0.03%)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
merged-by-bors This PR was explicitly merged by bors. S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. T-libs Relevant to the library team, which will review and decide on the PR/issue.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants