[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]

Re: [Libevent-users] evtimer_new "leak"



On Mon, Oct 06, 2014 at 04:50:13PM -0700, Michael Herf wrote:
> I wrote some code that was leaking on every call to evtimer_new -- I
> was definitely calling evtimer_del afterwards (sometimes before the
> timer fired).
> 
> To fix the leak, I found out I actually needed to call event_free,
> instead. Took me a while to go read the libevent code and figure
> this out.
> 
> This seems kinda confusing API-wise, and if my understanding of it
> is correct, adding an "evtimer_free" macro (also, evsignal_free,
> ...) or a better explanation could save people some time.
> 

+1 on having evtimer_free(). Though the best explanation is the
following:

"As a convenience, there are a set of macros beginning with evtimer_
that you can use in place of the event_* calls to allocate and
manipulate pure-timeout events. Using these macros provides no benefit
beyond improving the clarity of your code."

Note where it states it provides no benefit beyond the readability of
your code.

Casually scanning your code, what pops out more as a timer than any
other type of event? 

This?

  struct event * ev = event_new(base, -1, 0, callback, NULL);
  struct timeval tv = { 1, 0 };

  event_add(ev, &tv);

Or this?

   struct event * ev = evtimer_new(base, callback, NULL);
   struct timeval tv = { 1, 0 };

   evtimer_add(ev, &tv);


***********************************************************************
To unsubscribe, send an e-mail to majordomo@xxxxxxxxxxxxx with
unsubscribe libevent-users    in the body.