From fca0c4a53762e3437a2aea41d9d3e589cfae287a Mon Sep 17 00:00:00 2001 From: JP-Ellis Date: Tue, 12 Mar 2024 16:36:43 +1100 Subject: [PATCH] fix: binary body lifetime issue There's a subtle lifetime issue created in the original code. The original code uses: - `Bytes::from(&'static [u8])` - `from_raw_parts<'a, T>(*const T, usize) -> &'a [T]` Which requires the `*const T` pointer be a static pointer. Being provided through the FFI, this is unreasonable, and we should expect it to last only as long as the function call itself. By simply replacing `Bytes::from` with `Bytes::from_from_slice`, we narrow down the lifetime from `'static` to `'a`, allowing for the underlying `*const T` pointer to be deallocated once the function has returned. Signed-off-by: JP-Ellis --- rust/pact_ffi/src/mock_server/handles.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/rust/pact_ffi/src/mock_server/handles.rs b/rust/pact_ffi/src/mock_server/handles.rs index 249ccb4f0..9b788540f 100644 --- a/rust/pact_ffi/src/mock_server/handles.rs +++ b/rust/pact_ffi/src/mock_server/handles.rs @@ -2233,7 +2233,7 @@ fn convert_ptr_to_body(body: *const u8, size: size_t, content_type: Option