From 58f74083dad2226d63b0588ccd6c16e4421e422e Mon Sep 17 00:00:00 2001 From: prql-bot <107324867+prql-bot@users.noreply.github.com> Date: Wed, 25 Mar 2026 06:51:22 +0000 Subject: [PATCH] fix: correct Vec::from_raw_parts element type in prqlc-c The `result_destroy` function was using `*mut i8` as the element type when reconstructing the Vec for deallocation, but the original allocation was `Vec`. 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` 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 --- prqlc/bindings/prqlc-c/src/lib.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/prqlc/bindings/prqlc-c/src/lib.rs b/prqlc/bindings/prqlc-c/src/lib.rs index 81c1011608b8..6e753230a79f 100644 --- a/prqlc/bindings/prqlc-c/src/lib.rs +++ b/prqlc/bindings/prqlc-c/src/lib.rs @@ -236,7 +236,7 @@ pub unsafe extern "C" fn result_destroy(res: CompileResult) { } } drop(Vec::from_raw_parts( - res.messages as *mut i8, + res.messages as *mut Message, res.messages_len, res.messages_len, ));