ocaml: Nullify custom block before releasing runtime lock

Avoids a potential, though if possible then very rare, double free
path.

Suggested-by: Guillaume Munch-Maccagnoni
See: https://github.com/ocaml/ocaml/issues/12820
This commit is contained in:
Richard W.M. Jones
2023-12-14 08:33:10 +00:00
parent 61418535ad
commit e93fd7e8ac

View File

@@ -156,6 +156,9 @@ guestfs_int_ocaml_close (value gv)
size_t len; size_t len;
value **roots = get_all_event_callbacks (g, &len); value **roots = get_all_event_callbacks (g, &len);
/* So we don't double-free. */
Guestfs_val (gv) = NULL;
/* Close the handle: this could invoke callbacks from the list /* Close the handle: this could invoke callbacks from the list
* above, which is why we don't want to delete them before * above, which is why we don't want to delete them before
* closing the handle. * closing the handle.
@@ -173,9 +176,6 @@ guestfs_int_ocaml_close (value gv)
} }
free (roots); free (roots);
} }
/* So we don't double-free. */
Guestfs_val (gv) = NULL;
} }
CAMLreturn (Val_unit); CAMLreturn (Val_unit);