From bab6938f550041a575fbd0761290267b5b43b11d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ole=20Andr=C3=A9=20Vadla=20Ravn=C3=A5s?= Date: Tue, 4 Oct 2016 17:07:00 +0000 Subject: Fix memory-leaks by avoiding field initializers for generic fields Discussed this briefly with upstream on IRC, and it was concluded that this should probably have been forbidden by the Vala compiler in the first place. https://bugzilla.gnome.org/show_bug.cgi?id=772417 --- gee/concurrentset.vala | 3 ++- gee/lazy.vala | 3 ++- gee/priorityqueue.vala | 7 ++----- gee/promise.vala | 12 ++++++++++-- 4 files changed, 16 insertions(+), 9 deletions(-) diff --git a/gee/concurrentset.vala b/gee/concurrentset.vala index dc4b249..c5bfce9 100644 --- a/gee/concurrentset.vala +++ b/gee/concurrentset.vala @@ -34,6 +34,7 @@ public class Gee.ConcurrentSet : AbstractSortedSet { compare_func = Functions.get_compare_func_for (typeof (G)); } _cmp = (owned)compare_func; + _head = new Tower.head (); } ~ConcurrentSet () { @@ -246,7 +247,7 @@ public class Gee.ConcurrentSet : AbstractSortedSet { #endif private int _size = 0; - private Tower _head = new Tower.head (); + private Tower _head; private CompareDataFunc? _cmp; private const int _MAX_HEIGHT = 31; private static Private rand = new Private((ptr) => { diff --git a/gee/lazy.vala b/gee/lazy.vala index 00c34ba..5e7bc36 100644 --- a/gee/lazy.vala +++ b/gee/lazy.vala @@ -75,6 +75,7 @@ public class Gee.Lazy { private class Future : Object, Gee.Future { public Future (Lazy lazy) { _lazy = lazy; + _when_done = new Gee.Future.SourceFuncArrayElement[0]; } public bool ready { @@ -160,7 +161,7 @@ public class Gee.Lazy { private Cond _eval = Cond (); private Lazy _lazy; private State _state = State.UNLOCK; - private Gee.Future.SourceFuncArrayElement[]? _when_done = new Gee.Future.SourceFuncArrayElement[0]; + private Gee.Future.SourceFuncArrayElement[]? _when_done; private enum State { UNLOCK, EVAL diff --git a/gee/priorityqueue.vala b/gee/priorityqueue.vala index 31be4ab..e32b05a 100644 --- a/gee/priorityqueue.vala +++ b/gee/priorityqueue.vala @@ -60,11 +60,7 @@ public class Gee.PriorityQueue : Gee.AbstractQueue { private Type2Node? _lm_head = null; private Type2Node? _lm_tail = null; private Type1Node? _p = null; -#if VALA_0_16 - private Type1Node?[] _a = new Type1Node?[0]; -#else - private Type1Node?[] _a = new Type1Node[0]; -#endif + private Type1Node?[] _a; private NodePair? _lp_head = null; private unowned NodePair? _lp_tail = null; private bool[] _b = new bool[0]; @@ -87,6 +83,7 @@ public class Gee.PriorityQueue : Gee.AbstractQueue { compare_func = Functions.get_compare_func_for (typeof (G)); } _compare_func = (owned)compare_func; + _a = new Type1Node?[0]; } /** diff --git a/gee/promise.vala b/gee/promise.vala index 90eac07..401014d 100644 --- a/gee/promise.vala +++ b/gee/promise.vala @@ -34,6 +34,10 @@ using GLib; * @since 0.11.0 */ public class Gee.Promise { + public Promise () { + _future = new Future (); + } + ~Promise () { _future.abandon (); } @@ -66,6 +70,10 @@ public class Gee.Promise { } private class Future : Object, Gee.Future { + public Future () { + _when_done = new Gee.Future.SourceFuncArrayElement[0]; + } + public bool ready { get { _mutex.lock (); @@ -196,7 +204,7 @@ public class Gee.Promise { private State _state; private G? _value; private GLib.Error? _exception; - private Gee.Future.SourceFuncArrayElement[]? _when_done = new Gee.Future.SourceFuncArrayElement[0]; + private Gee.Future.SourceFuncArrayElement[]? _when_done; private enum State { INIT, @@ -205,6 +213,6 @@ public class Gee.Promise { READY } } - private Future _future = new Future(); + private Future _future; } -- cgit v1.2.1