Remove all `free`s in shmffi and ocaml_blob except onenightly-2022.06.07
commit9111580f491251d4233a5428e56f769b7c59d9da
authorJake Bailey <jakebailey@fb.com>
Tue, 7 Jun 2022 02:24:34 +0000 (6 19:24 -0700)
committerFacebook GitHub Bot <facebook-github-bot@users.noreply.github.com>
Tue, 7 Jun 2022 02:24:34 +0000 (6 19:24 -0700)
tree2be1fcb35994a9df1e829a851e20c442257a0526
parentbaae31ad1c2c9c8c32e4abfe8c547e9f551ffae4
Remove all `free`s in shmffi and ocaml_blob except one

Summary:
We are constrained to do one `free` because `caml_output_value_to_malloc` uses `malloc`, but we can actually avoid `free` in every other instance where it's used here. Wrap the use of `free` in a `Drop` impl for a new struct `MallocBuf`, representing the memory allocated by `caml_output_value_to_malloc`.

Since we use `MallocBuf` in `SerializedValue::Serialized`, `SerializedValue::from_heap_value` would need to use `malloc` (or similar) to construct a `SerializedValue::Serialized`. But we don't actually need a `from_heap_value` method, since it's only used in `shmffi_move`, which only needs to copy the heap value header and its data (which is just a byte slice).

Differential Revision: D36879767

fbshipit-source-id: 689d4c74e061d9a1d21bef78ea0465970b501afd
hphp/hack/Cargo.lock
hphp/hack/src/shmffi/cargo/ocaml_blob/Cargo.toml
hphp/hack/src/shmffi/ocaml_blob.rs
hphp/hack/src/shmffi/shmffi.rs