diff options
author | Rico Tzschichholz <ricotz@ubuntu.com> | 2020-12-31 09:55:16 +0100 |
---|---|---|
committer | Rico Tzschichholz <ricotz@ubuntu.com> | 2020-12-31 10:33:11 +0100 |
commit | af63cf9ac9243d404beb59100316ba2b2f914f68 (patch) | |
tree | 83d56e0df7a70142a6a17d31024f8689a52b7fd9 /codegen | |
parent | 72d641014cfc470a35d8a8722e19301730d41c98 (diff) | |
download | vala-af63cf9ac9243d404beb59100316ba2b2f914f68.tar.gz |
codegen: Don't leak memory of already assigned out-parameter on error
Fixes https://gitlab.gnome.org/GNOME/vala/issues/1123
Diffstat (limited to 'codegen')
-rw-r--r-- | codegen/valaccodebasemodule.vala | 11 | ||||
-rw-r--r-- | codegen/valagasyncmodule.vala | 4 | ||||
-rw-r--r-- | codegen/valagerrormodule.vala | 6 |
3 files changed, 21 insertions, 0 deletions
diff --git a/codegen/valaccodebasemodule.vala b/codegen/valaccodebasemodule.vala index b1f7e6869..b7db31835 100644 --- a/codegen/valaccodebasemodule.vala +++ b/codegen/valaccodebasemodule.vala @@ -3972,6 +3972,17 @@ public abstract class Vala.CCodeBaseModule : CodeGenerator { } } + public void append_out_param_free (Method? m) { + if (m == null) { + return; + } + foreach (Parameter param in m.get_parameters ()) { + if (param.direction == ParameterDirection.OUT && param.variable_type.is_disposable ()) { + ccode.add_expression (destroy_parameter (param)); + } + } + } + public bool variable_accessible_in_finally (LocalVariable local) { if (current_try == null) { return false; diff --git a/codegen/valagasyncmodule.vala b/codegen/valagasyncmodule.vala index f39f86c6e..c9946599f 100644 --- a/codegen/valagasyncmodule.vala +++ b/codegen/valagasyncmodule.vala @@ -743,8 +743,12 @@ public class Vala.GAsyncModule : GtkModule { set_error.add_argument (error_expr); ccode.add_expression (set_error); + // free local variables append_local_free (current_symbol); + // free possibly already assigned out-parameter + append_out_param_free (current_method); + // We already returned the error above, we must not return anything else here. var unref = new CCodeFunctionCall (new CCodeIdentifier ("g_object_unref")); unref.add_argument (async_result_expr); diff --git a/codegen/valagerrormodule.vala b/codegen/valagerrormodule.vala index fedc424ae..d724c3c3a 100644 --- a/codegen/valagerrormodule.vala +++ b/codegen/valagerrormodule.vala @@ -104,6 +104,9 @@ public class Vala.GErrorModule : CCodeDelegateModule { // free local variables append_local_free (current_symbol); + // free possibly already assigned out-parameter + append_out_param_free (current_method); + if (current_method is CreationMethod && current_method.parent_symbol is Class) { var cl = (Class) current_method.parent_symbol; ccode.add_expression (destroy_value (new GLibValue (new ObjectType (cl), new CCodeIdentifier ("self"), true))); @@ -123,6 +126,9 @@ public class Vala.GErrorModule : CCodeDelegateModule { append_local_free (current_symbol); } + // free possibly already assigned out-parameter + append_out_param_free (current_method); + cfile.add_include ("glib.h"); var ccritical = new CCodeFunctionCall (new CCodeIdentifier ("g_critical")); |