diff options
author | Ole André Vadla Ravnås <oleavr@gmail.com> | 2016-10-04 17:07:00 +0000 |
---|---|---|
committer | Maciej Piechotka <uzytkownik2@gmail.com> | 2016-10-11 23:07:43 -0700 |
commit | bab6938f550041a575fbd0761290267b5b43b11d (patch) | |
tree | 7dd6fdabb436b900e294b794c66b8e761287a56b | |
parent | 707456e37bded83b28d8bb8e21bab80c02359611 (diff) | |
download | libgee-bab6938f550041a575fbd0761290267b5b43b11d.tar.gz |
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
-rw-r--r-- | gee/concurrentset.vala | 3 | ||||
-rw-r--r-- | gee/lazy.vala | 3 | ||||
-rw-r--r-- | gee/priorityqueue.vala | 7 | ||||
-rw-r--r-- | 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<G> : AbstractSortedSet<G> { compare_func = Functions.get_compare_func_for (typeof (G)); } _cmp = (owned)compare_func; + _head = new Tower<G>.head (); } ~ConcurrentSet () { @@ -246,7 +247,7 @@ public class Gee.ConcurrentSet<G> : AbstractSortedSet<G> { #endif private int _size = 0; - private Tower<G> _head = new Tower<G>.head (); + private Tower<G> _head; private CompareDataFunc<G>? _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<G> { private class Future<G> : Object, Gee.Future<G> { public Future (Lazy<G> lazy) { _lazy = lazy; + _when_done = new Gee.Future.SourceFuncArrayElement<G>[0]; } public bool ready { @@ -160,7 +161,7 @@ public class Gee.Lazy<G> { private Cond _eval = Cond (); private Lazy<G> _lazy; private State _state = State.UNLOCK; - private Gee.Future.SourceFuncArrayElement<G>[]? _when_done = new Gee.Future.SourceFuncArrayElement<G>[0]; + private Gee.Future.SourceFuncArrayElement<G>[]? _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<G> : Gee.AbstractQueue<G> { private Type2Node<G>? _lm_head = null; private Type2Node<G>? _lm_tail = null; private Type1Node<G>? _p = null; -#if VALA_0_16 - private Type1Node<G>?[] _a = new Type1Node<G>?[0]; -#else - private Type1Node<G>?[] _a = new Type1Node<G>[0]; -#endif + private Type1Node<G>?[] _a; private NodePair<G>? _lp_head = null; private unowned NodePair<G>? _lp_tail = null; private bool[] _b = new bool[0]; @@ -87,6 +83,7 @@ public class Gee.PriorityQueue<G> : Gee.AbstractQueue<G> { compare_func = Functions.get_compare_func_for (typeof (G)); } _compare_func = (owned)compare_func; + _a = new Type1Node<G>?[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<G> { + public Promise () { + _future = new Future<G> (); + } + ~Promise () { _future.abandon (); } @@ -66,6 +70,10 @@ public class Gee.Promise<G> { } private class Future<G> : Object, Gee.Future<G> { + public Future () { + _when_done = new Gee.Future.SourceFuncArrayElement<G>[0]; + } + public bool ready { get { _mutex.lock (); @@ -196,7 +204,7 @@ public class Gee.Promise<G> { private State _state; private G? _value; private GLib.Error? _exception; - private Gee.Future.SourceFuncArrayElement<G>[]? _when_done = new Gee.Future.SourceFuncArrayElement<G>[0]; + private Gee.Future.SourceFuncArrayElement<G>[]? _when_done; private enum State { INIT, @@ -205,6 +213,6 @@ public class Gee.Promise<G> { READY } } - private Future<G> _future = new Future<G>(); + private Future<G> _future; } |