]> git.ipfire.org Git - thirdparty/vala.git/commitdiff
codegen: Don't cause double-free due append_local_free() in uncaught-errors
authorRico Tzschichholz <ricotz@ubuntu.com>
Thu, 29 Aug 2019 14:38:25 +0000 (16:38 +0200)
committerRico Tzschichholz <ricotz@ubuntu.com>
Mon, 2 Sep 2019 09:47:32 +0000 (11:47 +0200)
See https://gitlab.gnome.org/GNOME/vala/issues/838

codegen/valagerrormodule.vala

index 2abd5a4cef54dd504da0e0f87ac1c450673074b2..c64b410d5ecdb38b125b5d4733f94d1afc3e55e8 100644 (file)
@@ -117,9 +117,13 @@ public class Vala.GErrorModule : CCodeDelegateModule {
                }
        }
 
-       void uncaught_error_statement (CCodeExpression inner_error, bool unexpected = false) {
+       void uncaught_error_statement (CCodeExpression inner_error, bool unexpected = false, CodeNode? start_at = null) {
                // free local variables
-               append_local_free (current_symbol);
+               if (start_at is TryStatement) {
+                       append_local_free (start_at.parent_node as Block);
+               } else {
+                       append_local_free (current_symbol);
+               }
 
                var ccritical = new CCodeFunctionCall (new CCodeIdentifier ("g_critical"));
                ccritical.add_argument (new CCodeConstant (unexpected ? "\"file %s: line %d: unexpected error: %s (%s, %d)\"" : "\"file %s: line %d: uncaught error: %s (%s, %d)\""));
@@ -256,7 +260,7 @@ public class Vala.GErrorModule : CCodeDelegateModule {
                                // as jump out of finally block is not supported
                        } else {
                                // should never happen with correct bindings
-                               uncaught_error_statement (get_inner_error_cexpression (), true);
+                               uncaught_error_statement (get_inner_error_cexpression (), true, current_try);
                        }
                } else if (current_method != null && current_method.tree_can_fail) {
                        // current method can fail, propagate error