Instead of using the valid_flag == FREE mechanism, use a free callback
to free each closure root.
---
generator/generator | 9 +++++----
1 file changed, 5 insertions(+), 4 deletions(-)
diff --git a/generator/generator b/generator/generator
index 92ce170..109fad6 100755
--- a/generator/generator
+++ b/generator/generator
@@ -5239,9 +5239,6 @@ let print_ocaml_binding (name, { args; optargs; ret }) =
pr " caml_enter_blocking_section ();\n";
pr " }\n";
pr "\n";
- pr " if (valid_flag & LIBNBD_CALLBACK_FREE)\n";
- pr " free_root (NULL, user_data);\n";
- pr "\n";
pr " return ret;\n";
pr "}\n";
pr "\n"
@@ -5348,7 +5345,11 @@ let print_ocaml_binding (name, { args; optargs; ret }) =
pr " if (%s_user_data == NULL) caml_raise_out_of_memory ();\n" cbname;
pr " *%s_user_data = %sv;\n" cbname cbname;
pr " caml_register_generational_global_root (%s_user_data);\n" cbname;
- pr " const void *%s_callback = %s_%s_wrapper;\n" cbname name cbname
+ pr " const void *%s_callback = %s_%s_wrapper;\n" cbname name cbname;
+ pr " if (nbd_add_free_callback (h, %s_user_data,\n" cbname;
+ pr " free_root, %s_user_data) == -1)\n"
+ cbname;
+ pr " caml_raise_out_of_memory ();\n"
| Enum (n, { enum_prefix }) ->
pr " int %s = %s_val (%sv);\n" n enum_prefix n
| Flags (n, { flag_prefix }) ->
--
2.22.0