summaryrefslogtreecommitdiffstats
path: root/ocaml
diff options
context:
space:
mode:
authorRichard Jones <rjones@redhat.com>2009-04-30 14:01:53 +0100
committerRichard Jones <rjones@redhat.com>2009-04-30 14:01:53 +0100
commitab0397017cc26833c09946cca19d86b907822a94 (patch)
tree6bed84d3921570c84e7e6d9d9fc7b16889aa7c92 /ocaml
parent6f5c3984a7ddfc111287e2ec214ba823db737db4 (diff)
downloadlibguestfs-ab0397017cc26833c09946cca19d86b907822a94.tar.gz
libguestfs-ab0397017cc26833c09946cca19d86b907822a94.tar.xz
libguestfs-ab0397017cc26833c09946cca19d86b907822a94.zip
Use safe_malloc and/or check returns from malloc (Jim Meyering).
Diffstat (limited to 'ocaml')
-rw-r--r--ocaml/guestfs_c.c10
-rw-r--r--ocaml/guestfs_c.h2
-rw-r--r--ocaml/guestfs_c_actions.c10
3 files changed, 13 insertions, 9 deletions
diff --git a/ocaml/guestfs_c.c b/ocaml/guestfs_c.c
index 87139b48..86fa2939 100644
--- a/ocaml/guestfs_c.c
+++ b/ocaml/guestfs_c.c
@@ -111,15 +111,19 @@ ocaml_guestfs_close (value gv)
CAMLreturn (Val_unit);
}
-/* Copy string array value. */
+/* Copy string array value.
+ * The return value is only 'safe' provided we don't allocate anything
+ * further on the OCaml heap (ie. cannot trigger the OCaml GC) because
+ * that could move the strings around.
+ */
char **
-ocaml_guestfs_strings_val (value sv)
+ocaml_guestfs_strings_val (guestfs_h *g, value sv)
{
CAMLparam1 (sv);
char **r;
int i;
- r = malloc (sizeof (char *) * (Wosize_val (sv) + 1));
+ r = guestfs_safe_malloc (g, sizeof (char *) * (Wosize_val (sv) + 1));
for (i = 0; i < Wosize_val (sv); ++i)
r[i] = String_val (Field (sv, i));
r[i] = NULL;
diff --git a/ocaml/guestfs_c.h b/ocaml/guestfs_c.h
index 4fb81881..b4a76617 100644
--- a/ocaml/guestfs_c.h
+++ b/ocaml/guestfs_c.h
@@ -22,7 +22,7 @@
#define Guestfs_val(v) (*((guestfs_h **)Data_custom_val(v)))
extern void ocaml_guestfs_raise_error (guestfs_h *g, const char *func)
Noreturn;
-extern char **ocaml_guestfs_strings_val (value sv);
+extern char **ocaml_guestfs_strings_val (guestfs_h *g, value sv);
extern void ocaml_guestfs_free_strings (char **r);
#endif /* GUESTFS_OCAML_C_H */
diff --git a/ocaml/guestfs_c_actions.c b/ocaml/guestfs_c_actions.c
index b8c07878..9f860bad 100644
--- a/ocaml/guestfs_c_actions.c
+++ b/ocaml/guestfs_c_actions.c
@@ -1744,7 +1744,7 @@ ocaml_guestfs_vgcreate (value gv, value volgroupv, value physvolsv)
caml_failwith ("vgcreate: used handle after closing it");
const char *volgroup = String_val (volgroupv);
- char **physvols = ocaml_guestfs_strings_val (physvolsv);
+ char **physvols = ocaml_guestfs_strings_val (g, physvolsv);
int r;
caml_enter_blocking_section ();
@@ -1822,7 +1822,7 @@ ocaml_guestfs_sfdisk (value gv, value devicev, value cylsv, value headsv, value
int cyls = Int_val (cylsv);
int heads = Int_val (headsv);
int sectors = Int_val (sectorsv);
- char **lines = ocaml_guestfs_strings_val (linesv);
+ char **lines = ocaml_guestfs_strings_val (g, linesv);
int r;
caml_enter_blocking_section ();
@@ -1993,7 +1993,7 @@ ocaml_guestfs_command (value gv, value argumentsv)
if (g == NULL)
caml_failwith ("command: used handle after closing it");
- char **arguments = ocaml_guestfs_strings_val (argumentsv);
+ char **arguments = ocaml_guestfs_strings_val (g, argumentsv);
char *r;
caml_enter_blocking_section ();
@@ -2018,7 +2018,7 @@ ocaml_guestfs_command_lines (value gv, value argumentsv)
if (g == NULL)
caml_failwith ("command_lines: used handle after closing it");
- char **arguments = ocaml_guestfs_strings_val (argumentsv);
+ char **arguments = ocaml_guestfs_strings_val (g, argumentsv);
int i;
char **r;
@@ -2619,7 +2619,7 @@ ocaml_guestfs_debug (value gv, value subcmdv, value extraargsv)
caml_failwith ("debug: used handle after closing it");
const char *subcmd = String_val (subcmdv);
- char **extraargs = ocaml_guestfs_strings_val (extraargsv);
+ char **extraargs = ocaml_guestfs_strings_val (g, extraargsv);
char *r;
caml_enter_blocking_section ();