Pino Toscano
2016-Dec-12 13:03 UTC
[Libguestfs] [PATCH] java: fix memory leak in RStruct actions
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
Pino Toscano
2016-Dec-12 13:03 UTC
[Libguestfs] [PATCH] perl: fix memory leak in RStruct actions
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
Richard W.M. Jones
2016-Dec-12 19:32 UTC
Re: [Libguestfs] [PATCH] perl: fix memory leak in RStruct actions
On Mon, Dec 12, 2016 at 02:03:23PM +0100, Pino Toscano wrote:> 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 () > --ACK both. Rich. -- Richard Jones, Virtualization Group, Red Hat http://people.redhat.com/~rjones Read my programming and virtualization blog: http://rwmj.wordpress.com libguestfs lets you edit virtual machines. Supports shell scripting, bindings from many languages. http://libguestfs.org
Seemingly Similar Threads
- [PATCH] java: fix memory leak in RStruct actions
- [PATCH 1/2] Convert all TABs-as-indentation to spaces.
- [PATCH] python: check return value of Python APIs
- [Bug #1406906] [PATCH] python: fix segmentation fault when setting non UTF-8 strings
- [PATCH v2] RHBZ#1406906: check return value of Python object functions