fix: correct Vec::from_raw_parts element type in prqlc-c#5732
Merged
Conversation
The `result_destroy` function was using `*mut i8` as the element type when reconstructing the Vec for deallocation, but the original allocation was `Vec<Message>`. This mismatch causes undefined behavior because `Vec::from_raw_parts` requires the same type, alignment, and element size as the original allocation. Changed to `*mut Message` to match the original `Vec<Message>` allocation. Since `Message` is a `#[repr(C)]` struct with no `Drop` impl, the Vec drop simply deallocates the buffer without running element destructors, so there is no double-free risk with the manual field cleanup above. Closes #5731 Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
result_destroywhereVec::from_raw_partswas called with*mut i8instead of*mut Message, causing undefined behavior due to mismatched element type, alignment, and size vs. the originalVec<Message>allocation.Closes #5731
Test plan
cargo build -p prqlc-ccompiles successfullycargo test -p prqlc-cpasses🤖 Generated with Claude Code