Skip to content

fix: correct Vec::from_raw_parts element type in prqlc-c#5732

Merged
max-sixty merged 1 commit intomainfrom
fix/prqlc-c-vec-element-type
Mar 25, 2026
Merged

fix: correct Vec::from_raw_parts element type in prqlc-c#5732
max-sixty merged 1 commit intomainfrom
fix/prqlc-c-vec-element-type

Conversation

@prql-bot
Copy link
Copy Markdown
Collaborator

Summary

  • Fix memory safety bug in result_destroy where Vec::from_raw_parts was called with *mut i8 instead of *mut Message, causing undefined behavior due to mismatched element type, alignment, and size vs. the original Vec<Message> allocation.

Closes #5731

Test plan

  • cargo build -p prqlc-c compiles successfully
  • cargo test -p prqlc-c passes

🤖 Generated with Claude Code

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>
@prql-bot prql-bot enabled auto-merge (squash) March 25, 2026 06:51
@max-sixty max-sixty merged commit f55952a into main Mar 25, 2026
38 checks passed
@max-sixty max-sixty deleted the fix/prqlc-c-vec-element-type branch March 25, 2026 07:47
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.

Memory safety bug in prqlc-c: Vec::from_raw_parts with wrong element type

2 participants