ocaml-mysql icon indicating copy to clipboard operation
ocaml-mysql copied to clipboard

Unsafe use of enter/leave_blocking_section in C finalizers

Open gadmm opened this issue 2 years ago • 1 comments

https://github.com/ygrek/ocaml-mysql/blob/ac1fddf6cfcd9f80c55c11ab8856f9a4810ba5da/mysql_stubs.c#L175-L177

Here and in other finalization functions in this file, it is unsafe to use enter/leave_blocking_section in C finalizers, as per the documentation (this can cause the GC to run). If it worked until now somehow, this will definitely blow up in OCaml 5 which has even tighter constraints.

A possible workaround is to register finalization functions with Gc.finalize instead of the caml_alloc_final/the finalizer field of caml_alloc_custom. In this case one can call a C function that can use enter/leave_blocking_section.

gadmm avatar Jan 09 '23 16:01 gadmm

(see the discussion in ocaml/ocaml#11865)

gadmm avatar Jan 09 '23 16:01 gadmm