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

Correctly handle Vec with zero capacity in from_vec #332

Merged
merged 2 commits into from
Jan 13, 2024

Conversation

matzemathics
Copy link
Contributor

Since the standard library does not allocate any memory for vectors with capacity 0, the pointer returned by as_mut_ptr is dangling in that case. This causes a segfault, when shrink_to_fit tries to free.

waywardmonkeys and others added 2 commits January 13, 2024 12:09
When the capacity of the vec it zero, there might not have been
any memory allocated for it, thus the pointer obtained by
`as_mut_ptr` may dangle.
Copy link
Collaborator

@mbrubeck mbrubeck left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks!

@mbrubeck mbrubeck added this pull request to the merge queue Jan 13, 2024
Merged via the queue into servo:v2 with commit 944f603 Jan 13, 2024
6 checks passed
@matzemathics matzemathics deleted the fix-dealloc-dangling-ptr-from-vec-v2 branch January 14, 2024 11:28
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.

3 participants