If you need to copy the result of the caml_copy_string calls above into tmp, would it not be needed here as well? I think the risk here is that Store_field may allocate, not caml_copy_string or Val_int.

However, I actually thought Store_field would not allocate, and the original code was safe, because I have seen the ```Store_field(x, y, Val_bla(z))``` or even ```Store_field(x, y, caml_copy_string(z))``` pattern many times before. The former is present even in the OCaml docs.

Placing the output of caml_copy_string in a local variable would not harm, and therefore may be a good thing to do "just in case", but if you found that solved some segfaults, it makes me wonder if there are still some other unsafe bits of code...