[vala] GError: Fix leak when throwing an error in the constructor
- From: Jürg Billeter <juergbi src gnome org>
- To: svn-commits-list gnome org
- Cc:
- Subject: [vala] GError: Fix leak when throwing an error in the constructor
- Date: Wed, 27 Jan 2010 20:48:07 +0000 (UTC)
commit ec257a60267d843b22fb34f3cb5464a641104136
Author: Thijs Vermeir <thijsvermeir gmail com>
Date: Fri Oct 30 23:46:34 2009 +0100
GError: Fix leak when throwing an error in the constructor
Fixes bug 567818.
codegen/valagerrormodule.vala | 4 ++++
tests/Makefile.am | 1 +
tests/errors/bug567818.vala | 24 ++++++++++++++++++++++++
3 files changed, 29 insertions(+), 0 deletions(-)
---
diff --git a/codegen/valagerrormodule.vala b/codegen/valagerrormodule.vala
index ef25c06..b00438f 100644
--- a/codegen/valagerrormodule.vala
+++ b/codegen/valagerrormodule.vala
@@ -116,6 +116,10 @@ internal class Vala.GErrorModule : CCodeDelegateModule {
cerror_block.add_statement (free_frag);
if (current_method is CreationMethod) {
+ var cl = current_method.parent_symbol as Class;
+ var unref_call = new CCodeFunctionCall (new CCodeIdentifier (cl.get_unref_function ()));
+ unref_call.add_argument (new CCodeIdentifier ("self"));
+ cerror_block.add_statement (new CCodeExpressionStatement (unref_call));
cerror_block.add_statement (new CCodeReturnStatement (new CCodeConstant ("NULL")));
} else if (current_method != null && current_method.coroutine) {
cerror_block.add_statement (new CCodeReturnStatement (new CCodeConstant ("FALSE")));
diff --git a/tests/Makefile.am b/tests/Makefile.am
index e9628cd..783cd21 100644
--- a/tests/Makefile.am
+++ b/tests/Makefile.am
@@ -62,6 +62,7 @@ TESTS = \
objects/bug597155.vala \
objects/bug597161.vala \
errors/errors.vala \
+ errors/bug567818.vala \
errors/bug579101.vala \
errors/bug596228.vala \
asynchronous/bug595735.vala \
diff --git a/tests/errors/bug567818.vala b/tests/errors/bug567818.vala
new file mode 100644
index 0000000..3700d78
--- /dev/null
+++ b/tests/errors/bug567818.vala
@@ -0,0 +1,24 @@
+GLib.List<Foo> list;
+
+errordomain Error {
+ FOOBAR,
+}
+
+class Foo : Object {
+ public Foo () throws Error {
+ list.append (this);
+ throw new Error.FOOBAR ("foo");
+ }
+}
+
+void main () {
+ Foo foo = null;
+ list = new List<Foo> ();
+ try {
+ foo = new Foo ();
+ } catch (Error err) {
+ }
+ assert (foo == null);
+ /* There should be only 1 ref in the list */
+ assert (list.nth_data (0).ref_count == 1);
+}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]