Skip to content

Fix match scrutinee not being dropped#165

Draft
tothambrus11 wants to merge 1 commit into
enlightware:mainfrom
kyouko-taiga:fix/match-scrutinee-leak
Draft

Fix match scrutinee not being dropped#165
tothambrus11 wants to merge 1 commit into
enlightware:mainfrom
kyouko-taiga:fix/match-scrutinee-leak

Conversation

@tothambrus11

Copy link
Copy Markdown
Contributor

A match materializes its scrutinee into an owned local, but the block wrapping it is built with an empty cleanup list, so the local is never dropped.

When an arm binds the payload by reference the scrutinee stays live, so a resource-owning scrutinee leaks. The clearest case is a for-loop, which lowers to match next(it) { Some(x) => …, None => break } — the Option the iterator yields each iteration is never dropped.

The fix just adds the scrutinee local to the block's cleanup. The added test fails without it: the scrutinee's Probe drop never runs, so the recorded drop log is empty instead of 7.

A match materializes its scrutinee into an owned local, but the block wrapping it
is built with an empty cleanup list, so the local is never dropped. When an arm
binds the payload by reference the scrutinee stays live, so a resource-owning
scrutinee leaks. The clearest case is a for-loop, which lowers to
`match next(it) { Some(x) => …, None => break }`: the Option the iterator yields
each iteration is never dropped.

Adds the scrutinee local to the block's cleanup. The test fails without it (the
scrutinee's Probe drop never runs).
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant