-
Notifications
You must be signed in to change notification settings - Fork 12.7k
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
extend_from_within
leaks elements on panic
#82533
Comments
This is not unsafe, leaking items is safe: #24456. |
extend_from_within
extend_from_within
leaks items on panic
extend_from_within
leaks items on panicextend_from_within
leaks elements on panic
Sure; never said it was unsafe. This is more about making sure programs who gracefully handle panics don't wind up eventually exhausting resources. |
Assigning |
I would like to fix this @rustbot claim |
The fix seems pretty straight-forward. The Clone specialization just needs a RAII type that handles adjusting the Vec's new len in its Drop implementation, as I've linked in my MiniVec. Copy can't fail so there's no need to adjust that specialization. The only thing that could theoretically panic in that case would be reallocating and in that case, there's no need to worry about the len. |
rust/library/alloc/src/vec/mod.rs
Lines 2163 to 2182 in 98f8cce
Looking here, the internal length of the vector is only adjusted at the end of the loop
This has the caveat that if cloning panics, the Vec will start to unwind and only drop the first
len
elements which doesn't include the most recently appended ones.Something more in line with how the stdlib does things might look like this:
https://github.com/LeonineKing1199/minivec/blob/424354dfababae7101aacf70fa9332a87e9cdb15/src/lib.rs#L1612-L1700
The text was updated successfully, but these errors were encountered: