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
(cherry picked from commit e93fd7e8ac)
This commit is contained in:
Richard W.M. Jones
2023-12-14 08:33:10 +00:00
parent 836b63ce6d
commit a534de4f26

View File

@@ -156,6 +156,9 @@ guestfs_int_ocaml_close (value gv)
size_t 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
* above, which is why we don't want to delete them before
* closing the handle.
@@ -173,9 +176,6 @@ guestfs_int_ocaml_close (value gv)
}
free (roots);
}
/* So we don't double-free. */
Guestfs_val (gv) = NULL;
}
CAMLreturn (Val_unit);