eloop: fix eloop object never being freed
authorDavid Herrmann <dh.herrmann@googlemail.com>
Sun, 20 May 2012 20:54:08 +0000 (22:54 +0200)
committerDavid Herrmann <dh.herrmann@googlemail.com>
Sun, 20 May 2012 20:54:08 +0000 (22:54 +0200)
commitd3257fca31ee75b91c0915b9760fdd203c18ce3b
tree124cdacbaf64c890edd718999b2af720677e895e
parent00ff46b701213da02745f756db0ab9bae85634da
eloop: fix eloop object never being freed

We must _never_ take a reference to ourself in a constructor. Otherwise,
the refcnt will be >1 which means if the user calls *_unref() the object
will not get freed.
Therefore, do not add the counter object used for idle sources directly to
the event loop. Instead, add it when the first idle source is registered
and remove it when the last source is removed. This will slightly slow
down performance of idle-sources. However, the whole eloop is not
optimized for speed, yet, so we don't care for now.

Reported-by: Ran Benita <ran234@gmail.com>
Signed-off-by: David Herrmann <dh.herrmann@googlemail.com>
src/eloop.c