From: Rico Tzschichholz Date: Fri, 16 Sep 2016 14:54:21 +0000 (+0200) Subject: vala: Don't force array-elements to be owned, unowned ones are supported X-Git-Tag: 0.34.0~13 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=2ee9d3f5e4af2e73b8bc5d26044ac40f68232b3d;p=thirdparty%2Fvala.git vala: Don't force array-elements to be owned, unowned ones are supported Passing an (unowned string) array literal to a function causes the array elements to be freed afterwards, even though they should not be. This causes the array elements to be double freed. While assigning the literal to an intermediate variable and passing that to the function masks this error of the ArrayCreationExpression. https://bugzilla.gnome.org/show_bug.cgi?id=761307 --- diff --git a/tests/Makefile.am b/tests/Makefile.am index 23a46332c..58104cb0a 100644 --- a/tests/Makefile.am +++ b/tests/Makefile.am @@ -40,6 +40,7 @@ TESTS = \ basic-types/bug686336.vala \ basic-types/bug729907.vala \ basic-types/bug731017.vala \ + basic-types/bug761307.vala \ namespaces.vala \ methods/lambda.vala \ methods/closures.vala \ diff --git a/tests/basic-types/bug761307.vala b/tests/basic-types/bug761307.vala new file mode 100644 index 000000000..5e90dcfa3 --- /dev/null +++ b/tests/basic-types/bug761307.vala @@ -0,0 +1,12 @@ +void bar ((unowned string)[] str) { +} + +void foo () { + unowned string s1 = "ABC", s2 = "CDE"; + bar ({s1, s2}); + var s3 = "%s%s".printf (s1, s2); +} + +void main () { + foo (); +} diff --git a/vala/valaarraycreationexpression.vala b/vala/valaarraycreationexpression.vala index ec29ce800..589478421 100644 --- a/vala/valaarraycreationexpression.vala +++ b/vala/valaarraycreationexpression.vala @@ -239,8 +239,6 @@ public class Vala.ArrayCreationExpression : Expression { return false; } - element_type.value_owned = true; - value_type = new ArrayType (element_type, rank, source_reference); value_type.value_owned = true;