pact-foundation / pact-reference

Reference implementations for the pact specifications
https://pact.io
MIT License
91 stars 46 forks source link

fix: binary body lifetime issue #400

Closed JP-Ellis closed 6 months ago

JP-Ellis commented 6 months ago

There's a subtle lifetime issue created in the original code. The original code uses:

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.