[vala] Fix memory management when returning captured variables
- From: Jürg Billeter <juergbi src gnome org>
- To: svn-commits-list gnome org
- Cc:
- Subject: [vala] Fix memory management when returning captured variables
- Date: Tue, 29 Sep 2009 20:31:08 +0000 (UTC)
commit d73283631d0487b8361978a96994fd4a147568b8
Author: Jürg Billeter <j bitron ch>
Date: Tue Sep 29 22:29:58 2009 +0200
Fix memory management when returning captured variables
Fixes bug 596726.
codegen/valaccodebasemodule.vala | 8 ++++++--
tests/Makefile.am | 1 +
tests/methods/bug596726.vala | 16 ++++++++++++++++
3 files changed, 23 insertions(+), 2 deletions(-)
---
diff --git a/codegen/valaccodebasemodule.vala b/codegen/valaccodebasemodule.vala
index 8a1ce31..9f6cf10 100644
--- a/codegen/valaccodebasemodule.vala
+++ b/codegen/valaccodebasemodule.vala
@@ -2922,7 +2922,9 @@ internal class Vala.CCodeBaseModule : CCodeModule {
if (stmt.return_expression != null) {
var local = stmt.return_expression.symbol_reference as LocalVariable;
if (current_return_type.value_owned
- && local != null && local.variable_type.value_owned && !variable_accessible_in_finally (local)) {
+ && local != null && local.variable_type.value_owned
+ && !local.captured
+ && !variable_accessible_in_finally (local)) {
/* return expression is local variable taking ownership and
* current method is transferring ownership */
@@ -2957,7 +2959,9 @@ internal class Vala.CCodeBaseModule : CCodeModule {
// avoid unnecessary ref/unref pair
var local = stmt.return_expression.symbol_reference as LocalVariable;
if (current_return_type.value_owned
- && local != null && local.variable_type.value_owned && !variable_accessible_in_finally (local)) {
+ && local != null && local.variable_type.value_owned
+ && !local.captured
+ && !variable_accessible_in_finally (local)) {
/* return expression is local variable taking ownership and
* current method is transferring ownership */
diff --git a/tests/Makefile.am b/tests/Makefile.am
index 821b4a2..907f133 100644
--- a/tests/Makefile.am
+++ b/tests/Makefile.am
@@ -25,6 +25,7 @@ TESTS = \
methods/lambda.vala \
methods/closures.vala \
methods/bug595538.vala \
+ methods/bug596726.vala \
control-flow/break.vala \
control-flow/expressions-conditional.vala \
control-flow/for.vala \
diff --git a/tests/methods/bug596726.vala b/tests/methods/bug596726.vala
new file mode 100644
index 0000000..6eaec26
--- /dev/null
+++ b/tests/methods/bug596726.vala
@@ -0,0 +1,16 @@
+void do_bar (Func f) {
+}
+
+Object do_foo () {
+ var result = new Object ();
+
+ do_bar (() => {
+ var v = result;
+ });
+
+ return result;
+}
+
+void main () {
+ do_foo ();
+}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]