nbdkit/0009-ocaml-Always-unregister-the-global-root-and-free-the.patch
Richard W.M. Jones 3fc58c8fb6 Add all upstream patches
These are needed to get OCaml 5 to work.
2023-07-12 15:22:55 +01:00

66 lines
1.9 KiB
Diff

From f4d5f179c9be6db3c39bc0752e36f262c3f87716 Mon Sep 17 00:00:00 2001
From: "Richard W.M. Jones" <rjones@redhat.com>
Date: Wed, 21 Jun 2023 20:15:46 +0100
Subject: [PATCH 09/15] ocaml: Always unregister the global root and free the
handle
If the OCaml code did not provide a close method, we would never call
close_wrapper, and then we ended up leaking the global root and handle.
---
plugins/ocaml/plugin.c | 18 ++++++++++++++----
1 file changed, 14 insertions(+), 4 deletions(-)
diff --git a/plugins/ocaml/plugin.c b/plugins/ocaml/plugin.c
index fe781f9af..a4671d6ed 100644
--- a/plugins/ocaml/plugin.c
+++ b/plugins/ocaml/plugin.c
@@ -76,6 +76,7 @@ constructor (void)
* nbdkit_plugin struct and return it from our own plugin_init
* function.
*/
+static void close_wrapper (void *h);
static void unload_wrapper (void);
static void free_strings (void);
static void remove_roots (void);
@@ -92,6 +93,10 @@ static struct nbdkit_plugin plugin = {
*/
.name = NULL,
+ /* We always call these, even if the OCaml code does not provide a
+ * callback.
+ */
+ .close = close_wrapper,
.unload = unload_wrapper,
};
@@ -345,6 +350,9 @@ open_wrapper (int readonly)
CAMLreturnT (void *, ret);
}
+/* We always have a close function, since we need to unregister the
+ * global root and free the handle.
+ */
static void
close_wrapper (void *h)
{
@@ -352,10 +360,12 @@ close_wrapper (void *h)
CAMLparam0 ();
CAMLlocal1 (rv);
- rv = caml_callback_exn (close_fn, *(value *) h);
- if (Is_exception_result (rv)) {
- nbdkit_error ("%s", caml_format_exception (Extract_exception (rv)));
- /*FALLTHROUGH*/
+ if (close_fn) {
+ rv = caml_callback_exn (close_fn, *(value *) h);
+ if (Is_exception_result (rv)) {
+ nbdkit_error ("%s", caml_format_exception (Extract_exception (rv)));
+ /*FALLTHROUGH*/
+ }
}
caml_remove_generational_global_root (h);
--
2.41.0