[vala/0.48] vala: value_type of PointerIndirection expressions must not be owned



commit 1fc808749844f6dea7126586efe9982dcf88768e
Author: Rico Tzschichholz <ricotz ubuntu com>
Date:   Mon Dec 21 13:52:54 2020 +0100

    vala: value_type of PointerIndirection expressions must not be owned
    
    A member-access making the wrong assumption of a previous copy resulted
    in a double free.
    
    Fixes https://gitlab.gnome.org/GNOME/vala/issues/1118

 tests/Makefile.am                                        |  1 +
 .../semantic/localvariable-var-pointer-initializer.vala  | 16 ++++++++++++++++
 vala/valapointerindirection.vala                         |  1 +
 3 files changed, 18 insertions(+)
---
diff --git a/tests/Makefile.am b/tests/Makefile.am
index 028c0b900..0195b0990 100644
--- a/tests/Makefile.am
+++ b/tests/Makefile.am
@@ -874,6 +874,7 @@ TESTS = \
        semantic/interface-prerequisite-multiple.test \
        semantic/literal-expression.test \
        semantic/localvariable-owned-to-unowned.test \
+       semantic/localvariable-var-pointer-initializer.vala \
        semantic/localvariable-var-static-access-instance-field.test \
        semantic/localvariable-var-static-access-instance-method.test \
        semantic/localvariable-var-static-access-instance-property.test \
diff --git a/tests/semantic/localvariable-var-pointer-initializer.vala 
b/tests/semantic/localvariable-var-pointer-initializer.vala
new file mode 100644
index 000000000..42bafc943
--- /dev/null
+++ b/tests/semantic/localvariable-var-pointer-initializer.vala
@@ -0,0 +1,16 @@
+struct Foo {
+       public string s;
+}
+
+void main () {
+       {
+               Foo foo = { "foo" };
+               var foo_p = &foo;
+               assert (foo_p.s == "foo");
+       }
+       {
+               Foo bar = { "bar" };
+               unowned var bar_p = &bar;
+               assert (bar_p.s == "bar");
+       }
+}
diff --git a/vala/valapointerindirection.vala b/vala/valapointerindirection.vala
index 156194cb8..c7fc415a3 100644
--- a/vala/valapointerindirection.vala
+++ b/vala/valapointerindirection.vala
@@ -102,6 +102,7 @@ public class Vala.PointerIndirection : Expression {
                                return false;
                        }
                        value_type = pointer_type.base_type;
+                       value_type.value_owned = false;
                } else {
                        error = true;
                        Report.error (source_reference, "Pointer indirection not supported for this 
expression");


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