[vala] codegen: Do not treat void* to not leak memory anymore
- From: Luca Bruno <lucabru src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [vala] codegen: Do not treat void* to not leak memory anymore
- Date: Mon, 26 Sep 2011 20:15:28 +0000 (UTC)
commit 9c67e8be75dbaa83806a7978736e6c679f08f5fa
Author: Luca Bruno <lucabru src gnome org>
Date: Mon Sep 26 22:01:56 2011 +0200
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.
codegen/valaccodebasemodule.vala | 6 ++----
tests/Makefile.am | 1 +
tests/basic-types/bug659975.vala | 8 ++++++++
3 files changed, 11 insertions(+), 4 deletions(-)
---
diff --git a/codegen/valaccodebasemodule.vala b/codegen/valaccodebasemodule.vala
index a21c4d4..ee23a6d 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 5c8ddd3..098f646 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 0000000..aeba0f9
--- /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);
+}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]