]> git.ipfire.org Git - thirdparty/vala.git/commitdiff
codegen: Do not treat void* to not leak memory anymore
authorLuca Bruno <lucabru@src.gnome.org>
Mon, 26 Sep 2011 20:01:56 +0000 (22:01 +0200)
committerLuca Bruno <lucabru@src.gnome.org>
Mon, 26 Sep 2011 20:10:54 +0000 (22:10 +0200)
It wasn't possible to let void* variables take the ownership of
an expression as it's always been freed afterwards.
Simple generics can be used to enforce ownership instead of void*.

Fixes bug 659975.

codegen/valaccodebasemodule.vala
tests/Makefile.am
tests/basic-types/bug659975.vala [new file with mode: 0644]

index a21c4d4d7f3c3b1f56ceb94278bae634f004acfb..ee23a6dcdd1e87951d2d7a549f896a4092f14767 100644 (file)
@@ -5110,10 +5110,8 @@ public abstract class Vala.CCodeBaseModule : CodeGenerator {
                    && (target_type == null || !target_type.value_owned || boxing || unboxing)
                    && !gvalue_boxing /* gvalue can assume ownership of value, no need to free it */) {
                        // value leaked, destroy it
-                       var pointer_type = target_type as PointerType;
-                       if (pointer_type != null && !(pointer_type.base_type is VoidType)) {
-                               // manual memory management for non-void pointers
-                               // treat void* special to not leak memory with void* method parameters
+                       if (target_type is PointerType) {
+                               // manual memory management for pointers
                        } else if (requires_destroy (type)) {
                                var temp_value = create_temp_value (type, false, node);
                                temp_ref_values.insert (0, ((GLibValue) temp_value).copy ());
index 5c8ddd3115e657b786b7d55d575445884ec3c027..098f64654fa5fa2cab67fde9602f24fe1fec0f0e 100644 (file)
@@ -30,6 +30,7 @@ TESTS = \
        basic-types/bug650993.vala \
        basic-types/bug652380.vala \
        basic-types/bug655908.vala \
+       basic-types/bug659975.vala \
        namespaces.vala \
        methods/lambda.vala \
        methods/closures.vala \
diff --git a/tests/basic-types/bug659975.vala b/tests/basic-types/bug659975.vala
new file mode 100644 (file)
index 0000000..aeba0f9
--- /dev/null
@@ -0,0 +1,8 @@
+void foo (void* bar) {
+       string baz = (string) (owned) bar;
+}
+
+void main () {
+       var bar = "bar";
+       foo ((owned) bar);
+}