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

Pino Toscano ptoscano at redhat.com
Mon Dec 12 13:03:23 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/perl.ml | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/generator/perl.ml b/generator/perl.ml
index 290b687..4c7f805 100644
--- a/generator/perl.ml
+++ b/generator/perl.ml
@@ -657,7 +657,7 @@ and generate_perl_struct_code typ cols name style n =
           pr "      PUSHs (sv_2mortal (newSVnv (r->%s)));\n"
             name
   ) cols;
-  pr "      free (r);\n"
+  pr "      guestfs_free_%s (r);\n" typ
 
 (* Generate Sys/Guestfs.pm. *)
 and generate_perl_pm () =
-- 
2.7.4




More information about the Libguestfs mailing list