Clear caml_backtrace_last_exn before registering as root #205
Switching on backtrace recording registers
Testcase (tested with 4.02.1 and 4.02.2):
(* $ ocamlopt -g fail.ml $ ./a.out Segmentation fault *) let test arg = Gc.minor (); Printexc.record_backtrace true; begin try raise (Invalid_argument (Bytes.copy "lalala")) with _ -> () end; (* caml_backtrace_last_exn is now pointing to the exception *) Printexc.record_backtrace false; (* no longer a root *) Gc.minor (); (* minor heap clean, but caml_backtrace_last_exn still pointing to value *) ignore [arg; arg; arg]; (* allocate random stuff *) Printexc.record_backtrace true; (* again a root, pointing somewhere in minor heap *) Gc.minor () (* hopefully fails *) let () = while true do test (); done
@alainfrisch Of course, once fixed the test never finishes. I managed to have an easy to reproduce one with 4.02.1, but I had to introduce the loop for 4.02.2 (without satisfying reason, just to get to some wrong GC internal state). I think we can skip the test, I'll close the pull request :).