ocaml: Fix thread safety of strings in bindings (RHBZ#604691).
authorRichard Jones <rjones@redhat.com>
Wed, 16 Jun 2010 14:25:45 +0000 (15:25 +0100)
committerRichard Jones <rjones@redhat.com>
Wed, 16 Jun 2010 14:32:20 +0000 (15:32 +0100)
commit1079f74704a06c06996e547fdecf20a8f92799c6
tree32b272a9b86952f06f8565526c1fe5d8cf09bee7
parent1e568f057e8bb7b36cc14e0e531d74b75ad9cb6c
ocaml: Fix thread safety of strings in bindings (RHBZ#604691).

There's a thread safety issue with the current OCaml bindings which
is well explained in the bug report:

https://bugzilla.redhat.com/show_bug.cgi?id=604691

This commit fixes the safety issue by copying strings temporarily
before releasing the thread lock.  Updated code looks like this:

  char *filename = guestfs_safe_strdup (g, String_val (filenamev));
  int r;

  caml_enter_blocking_section ();
  r = guestfs_add_drive_ro (g, filename);
  caml_leave_blocking_section ();
  free (filename);
  if (r == -1)
    ocaml_guestfs_raise_error (g, "add_drive_ro");

Also included is a regression test.
.gitignore
ocaml/Makefile.am
ocaml/guestfs_c.c
ocaml/guestfs_c.h
ocaml/t/guestfs_070_threads.ml [new file with mode: 0644]
src/generator.ml