Skip to content

Segmentation fault on Windows with OCaml 4.12 #10477

@yallop

Description

@yallop

The Ctypes library has a test that checks that code generated by the library keeps objects alive while the runtime lock is released. The test consistently passes with all combinations of OCaml versions and operating systems, except one: OCaml 4.12 on Windows, where it fails with a segmentation fault.

Some investigation suggests that the bug is due to a problem in OCaml, introduced between 4.11 and 4.12. The following cut-down program (also available here) doesn't use ctypes, but does trigger segmentation faults fairly reliably:

let alloc () =
  for i = 0 to 20000 do
    for i = 0 to 200; do ignore (Array.make 10 ()) done;
    ignore (Array.make 1000 ());
    if i mod 1000 = 0 then (Gc.compact ());
  done

let churn () =
  let allocators = List.init 10 (fun _ -> Thread.create alloc ()) in
  List.iter Thread.join allocators

let () = churn ()

As the CI logs for the program show, on 4.11 the test runs reliably, while on 4.12 it segfaults every few runs.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions