From: Richard Jones Date: Wed, 15 Apr 2009 13:09:01 +0000 (+0100) Subject: Correctly free memory in RHashtable binding for OCaml & Python. X-Git-Tag: 0.9.2~2 X-Git-Url: http://git.annexia.org/?a=commitdiff_plain;h=0c2376a5c05053ce6a0479ade544be860c400fdb;p=libguestfs.git Correctly free memory in RHashtable binding for OCaml & Python. --- diff --git a/ocaml/guestfs_c_actions.c b/ocaml/guestfs_c_actions.c index b1c4652..a3186d1 100644 --- a/ocaml/guestfs_c_actions.c +++ b/ocaml/guestfs_c_actions.c @@ -1919,6 +1919,7 @@ ocaml_guestfs_tune2fs_l (value gv, value devicev) caml_failwith ("tune2fs_l: used handle after closing it"); const char *device = String_val (devicev); + int i; char **r; caml_enter_blocking_section (); @@ -1928,6 +1929,7 @@ ocaml_guestfs_tune2fs_l (value gv, value devicev) ocaml_guestfs_raise_error (g, "tune2fs_l"); rv = copy_table (r); + for (i = 0; r[i] != NULL; ++i) free (r[i]); free (r); CAMLreturn (rv); } diff --git a/python/guestfs-py.c b/python/guestfs-py.c index 8fbab74..21ecd54 100644 --- a/python/guestfs-py.c +++ b/python/guestfs-py.c @@ -2072,7 +2072,7 @@ py_guestfs_tune2fs_l (PyObject *self, PyObject *args) } py_r = put_table (r); - free (r); + free_strings (r); return py_r; } diff --git a/src/generator.ml b/src/generator.ml index b1071a8..c20e43f 100755 --- a/src/generator.ml +++ b/src/generator.ml @@ -3533,6 +3533,7 @@ copy_table (char * const * argv) | RStatVFS _ -> pr " struct guestfs_statvfs *r;\n"; "NULL" | RHashtable _ -> + pr " int i;\n"; pr " char **r;\n"; "NULL" in pr "\n"; @@ -3588,6 +3589,7 @@ copy_table (char * const * argv) pr " free (r);\n"; | RHashtable _ -> pr " rv = copy_table (r);\n"; + pr " for (i = 0; r[i] != NULL; ++i) free (r[i]);\n"; pr " free (r);\n"; ); @@ -4447,7 +4449,7 @@ py_guestfs_close (PyObject *self, PyObject *args) pr " free (r);\n" | RHashtable n -> pr " py_r = put_table (r);\n"; - pr " free (r);\n" + pr " free_strings (r);\n" ); pr " return py_r;\n";