[vala/wip/issue/838: 5/7] codegen: Don't cause double-free due append_local_free() in uncaught-errors



commit e2f188a185ed47c2f383840926a35eedd64b9bc4
Author: Rico Tzschichholz <ricotz ubuntu com>
Date:   Thu Aug 29 16:38:25 2019 +0200

    codegen: Don't cause double-free due append_local_free() in uncaught-errors
    
    See https://gitlab.gnome.org/GNOME/vala/issues/838

 codegen/valagerrormodule.vala | 10 +++++++---
 1 file changed, 7 insertions(+), 3 deletions(-)
---
diff --git a/codegen/valagerrormodule.vala b/codegen/valagerrormodule.vala
index 2abd5a4ce..c64b410d5 100644
--- a/codegen/valagerrormodule.vala
+++ b/codegen/valagerrormodule.vala
@@ -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


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]