]> git.ipfire.org Git - thirdparty/vala.git/commitdiff
codegen: Don't leak GLib.Value when implicitly unboxing it
authorRico Tzschichholz <ricotz@ubuntu.com>
Wed, 3 Feb 2021 12:40:23 +0000 (13:40 +0100)
committerRico Tzschichholz <ricotz@ubuntu.com>
Wed, 3 Feb 2021 13:29:12 +0000 (14:29 +0100)
Found by -fsanitize=address

codegen/valagvaluemodule.vala

index 0429085e6b44b8f1a1182759a1caa53bb28ced3f..f13022c265757e2e8e44a1c0f91bc4b15d3d64ef 100644 (file)
@@ -44,6 +44,17 @@ public class Vala.GValueModule : GAsyncModule {
                }
                ccall.add_argument (gvalue);
 
+               if (value_type.is_disposable ()) {
+                       var temp_var = get_temp_variable (value_type, true, expr, false);
+                       emit_temp_var (temp_var);
+                       var temp_ref = get_variable_cexpression (temp_var.name);
+                       ccode.add_assignment (temp_ref, get_cvalue (expr.inner));
+
+                       // value needs to be kept alive until the end of this block
+                       assert (current_symbol is Block);
+                       ((Block) current_symbol).add_local_variable (temp_var);
+               }
+
                CCodeExpression rv;
                if (target_type is ArrayType) {
                        var temp_var = get_temp_variable (target_type, true, expr, false);