[Libguestfs] [PATCH 4/4] php: fix memory leak in OStringList optargs

Pino Toscano ptoscano at redhat.com
Tue Feb 10 15:42:55 UTC 2015


Make sure to free the char** created to convert the arguments.
---
 generator/php.ml | 10 ++++++++++
 1 file changed, 10 insertions(+)

diff --git a/generator/php.ml b/generator/php.ml
index 28903d0..b49bf60 100644
--- a/generator/php.ml
+++ b/generator/php.ml
@@ -458,6 +458,16 @@ PHP_FUNCTION (guestfs_last_error)
             pr "\n"
         | Bool _ | Int _ | Int64 _ | Pointer _ -> ()
         ) args;
+      List.iter (
+        function
+        | OBool n | OInt n | OInt64 n | OString n -> ()
+        | OStringList n ->
+            let uc_n = String.uppercase n in
+            pr "  if ((optargs_s.bitmask & %s_%s_BITMASK) != 0)\n"
+              c_optarg_prefix uc_n;
+            pr "    guestfs_efree_stringlist ((char **) optargs_s.%s);\n" n;
+            pr "\n"
+      ) optargs;
 
       (* Check for errors. *)
       (match errcode_of_ret ret with
-- 
1.9.3




More information about the Libguestfs mailing list