Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Clear caml_backtrace_last_exn before registering as root #205

Closed
wants to merge 1 commit into from

Conversation

Projects
None yet
3 participants
@let-def
Copy link
Contributor

commented Jun 23, 2015

Switching on backtrace recording registers caml_backtrace_last_exn as a global root, switching it off removes it.
But the value is never cleared, so that an arbitrary pointer to the ocaml heap can end up there and corrupts the GC.

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

@let-def let-def force-pushed the let-def:fix-backtrace branch from f866b87 to 3c364b8 Jun 23, 2015

@xavierleroy

This comment has been minimized.

Copy link
Contributor

commented Jun 23, 2015

Well spotted. OK for applying the proposed fix.

@alainfrisch

This comment has been minimized.

Copy link
Contributor

commented Jun 23, 2015

Fix applied to trunk, rev 16187.

However, I don't manage to add a test in the suite (that finishes in finite time).

@let-def

This comment has been minimized.

Copy link
Contributor Author

commented Jul 1, 2015

@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 :).

@let-def let-def closed this Jul 1, 2015

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.