[Libguestfs] [PATCH] java: fix memory leak in RStruct actions

Pino Toscano ptoscano at redhat.com
Mon Dec 12 13:03:22 UTC 2016


The return value struct was freed using a simple free() instead of the
own cleanup function of each struct: this meant dynamically allocated
values (such as strings) were leaked.

Use the proper cleanup functions instead.
---
 generator/java.ml | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/generator/java.ml b/generator/java.ml
index a68054c..3c1e611 100644
--- a/generator/java.ml
+++ b/generator/java.ml
@@ -1000,7 +1000,7 @@ and generate_java_struct_return typ jtyp cols =
         pr "  fl = (*env)->GetFieldID (env, cl, \"%s\", \"C\");\n" name;
         pr "  (*env)->SetCharField (env, jr, fl, r->%s);\n" name;
   ) cols;
-  pr "  free (r);\n";
+  pr "  guestfs_free_%s (r);\n" typ;
   pr "  return jr;\n"
 
 and generate_java_struct_list_return typ jtyp cols =
-- 
2.7.4




More information about the Libguestfs mailing list