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

Fixed UB and implemented the Drop trait for atomic-queue #608

Merged
merged 1 commit into from
Jan 15, 2024

Conversation

sidit77
Copy link
Contributor

@sidit77 sidit77 commented Jan 3, 2024

If you have a reference &T, then normally in Rust the compiler performs optimizations based on the knowledge that &T points to immutable data. Mutating that data, for example through an alias or by transmuting an &T into an &mut T, is considered undefined behavior. UnsafeCell opts-out of the immutability guarantee for &T: a shared reference &UnsafeCell may point to data that is being mutated. This is called “interior mutability”.

Source
crossbeam-queue for reference.

I added the required UnsafeCells and also manually implemented the Drop trait as MaybeUninit<T> prevents the Drop implementation of T from running. This leads to memory leaks when the queue is used with types like String that use Drop to free thier memory.

@yamadapc
Copy link
Owner

Thank you!

@yamadapc yamadapc self-assigned this Jan 15, 2024
@yamadapc
Copy link
Owner

Follow-up for tests tracked by #609

@yamadapc yamadapc merged commit 607d8ca into yamadapc:master Jan 15, 2024
9 of 12 checks passed
@yamadapc
Copy link
Owner

Builds fail due to coveralls key missing on linux PR actions; which needs to be fixed.

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.

2 participants