From: Luca Bruno Date: Mon, 26 Sep 2011 20:01:56 +0000 (+0200) Subject: codegen: Do not treat void* to not leak memory anymore X-Git-Tag: 0.15.0~66 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=9c67e8be75dbaa83806a7978736e6c679f08f5fa;p=thirdparty%2Fvala.git codegen: Do not treat void* to not leak memory anymore 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. --- diff --git a/codegen/valaccodebasemodule.vala b/codegen/valaccodebasemodule.vala index a21c4d4d7..ee23a6dcd 100644 --- a/codegen/valaccodebasemodule.vala +++ b/codegen/valaccodebasemodule.vala @@ -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 ()); diff --git a/tests/Makefile.am b/tests/Makefile.am index 5c8ddd311..098f64654 100644 --- a/tests/Makefile.am +++ b/tests/Makefile.am @@ -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 index 000000000..aeba0f979 --- /dev/null +++ b/tests/basic-types/bug659975.vala @@ -0,0 +1,8 @@ +void foo (void* bar) { + string baz = (string) (owned) bar; +} + +void main () { + var bar = "bar"; + foo ((owned) bar); +}