]> git.ipfire.org Git - thirdparty/vala.git/commitdiff
vala: Don't force array-elements to be owned, unowned ones are supported
authorRico Tzschichholz <ricotz@ubuntu.com>
Fri, 16 Sep 2016 14:54:21 +0000 (16:54 +0200)
committerRico Tzschichholz <ricotz@ubuntu.com>
Fri, 16 Sep 2016 15:03:49 +0000 (17:03 +0200)
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

tests/Makefile.am
tests/basic-types/bug761307.vala [new file with mode: 0644]
vala/valaarraycreationexpression.vala

index 23a46332c1d410fb05783394b9ae85cfbbee1ad0..58104cb0a1899e154c73a3ba6e8e2538b2d0a57e 100644 (file)
@@ -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 (file)
index 0000000..5e90dcf
--- /dev/null
@@ -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 ();
+}
index ec29ce80077f380f006439d0880da98fd1e9f4fa..58947842118a4a29b674ea6a28a8f1a8d104f3d3 100644 (file)
@@ -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;