[vala] vala: Don't force array-elements to be owned, unowned ones are supported



commit 2ee9d3f5e4af2e73b8bc5d26044ac40f68232b3d
Author: Rico Tzschichholz <ricotz ubuntu com>
Date:   Fri Sep 16 16:54:21 2016 +0200

    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

 tests/Makefile.am                     |    1 +
 tests/basic-types/bug761307.vala      |   12 ++++++++++++
 vala/valaarraycreationexpression.vala |    2 --
 3 files changed, 13 insertions(+), 2 deletions(-)
---
diff --git a/tests/Makefile.am b/tests/Makefile.am
index 23a4633..58104cb 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 0000000..5e90dcf
--- /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 ec29ce8..5894784 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;
 


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