From: Rico Tzschichholz Date: Mon, 21 Dec 2020 12:52:54 +0000 (+0100) Subject: vala: value_type of PointerIndirection expressions must not be owned X-Git-Tag: 0.51.1~131 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=df7a984607f55338ff2dde6f2fd324dc363a46b4;p=thirdparty%2Fvala.git 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 --- diff --git a/tests/Makefile.am b/tests/Makefile.am index b620a847f..ddac20684 100644 --- a/tests/Makefile.am +++ b/tests/Makefile.am @@ -914,6 +914,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 6c17d3598..5e14de7f6 100644 --- a/vala/valapointerindirection.vala +++ b/vala/valapointerindirection.vala @@ -104,6 +104,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");