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

Crash when finalising lazy values of the wrong type. #6664

vicuna opened this issue Nov 18, 2014 · 2 comments

Crash when finalising lazy values of the wrong type. #6664

vicuna opened this issue Nov 18, 2014 · 2 comments


Copy link

@vicuna vicuna commented Nov 18, 2014

Original bug ID: 6664
Reporter: @damiendoligez
Assigned to: @damiendoligez
Status: closed (set by @damiendoligez on 2015-03-04T19:59:26Z)
Resolution: fixed
Priority: normal
Severity: minor
Platform: all
OS: all
OS Version: all
Version: 4.03.0+dev / +beta1
Target version: 4.03.0+dev / +beta1
Fixed in version: 4.03.0+dev / +beta1
Category: runtime system and C interface

Bug description

When you finalise a value of type [int lazy], you get a crash.
The problem is in caml_final_update, at finalise.c:94, short-circuiting the pointer makes a finalised int, which violates the invariants.

I'm not sure what the behavior should be in that case.

Steps to reproduce

With ocamlc, ocamlopt, or the toplevel:

let f x =
let r = ref (lazy (1+x)) in
let fin x = Printf.eprintf "finalisation %d\n%!" (Lazy.force x) in
Gc.finalise fin !r;
ignore (Lazy.force !r);
r := lazy 0;
Gc.full_major ();
f 3;;

Copy link

@vicuna vicuna commented Nov 24, 2014

Comment author: @damiendoligez

After thinking about it and discussing with some users, it seems clear that Gc.finalise should raise Invalid_argument when called on a lazy or a float, because these types are not (always) represented by heap blocks.

Unfortunately, the run-time test for lazy is not exact: some lazy values (the ones that are already forwarded) cannot be detected as such. This will have to be documented.

Copy link

@vicuna vicuna commented Mar 4, 2015

Comment author: @damiendoligez

fixed in trunk (commit 15876)

@vicuna vicuna closed this as completed Mar 4, 2015
@vicuna vicuna added the stdlib label Mar 14, 2019
@vicuna vicuna added this to the 4.03.0 milestone Mar 14, 2019
@vicuna vicuna added the bug label Mar 20, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
None yet

No branches or pull requests

2 participants