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

Why can pop_front() cause panic in 7.4 Panic Safety ? #303

Open
tjliupeng opened this issue Jul 18, 2024 · 0 comments
Open

Why can pop_front() cause panic in 7.4 Panic Safety ? #303

tjliupeng opened this issue Jul 18, 2024 · 0 comments

Comments

@tjliupeng
Copy link

tjliupeng commented Jul 18, 2024

in https://rust-unofficial.github.io/too-many-lists/sixth-panics.html, it says that the line

debug_assert!(self.len == 1);

can cause problem.

How?

There is a paragraph below to explain the cause:

We have our boxed_node on the stack, and we've extracted the element from it. If we were to return at this point, the Box would be dropped, and the node would be freed. Do you see it now..? self.back is still pointing at that freed node! Once we implement the rest of our collection and start using self.back for things, this could result in a use-after-free!

If the user just calls the API of this list, it is impossible to get to this situation.

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

No branches or pull requests

1 participant