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

Re: [Libevent-users] Crash in event_del



On Wed, Aug 11, 2010 at 12:00:09PM -0700, Gilad Benjamini wrote:
> My code currently runs with libevent 1.4
> While in the process of upgrading to libevent 2.0.6 I got a segfault.
> 
> Code sample is pretty basic
>   event_set(&ev,fd,EV_READ,fd_handler,NULL) ;
>   event_del(&ev) ;
> 
> The reason for the crash is pretty simple as well. event_del calls
> EVBASE_ACQUIRE_LOCK which assume that ev->ev_base is non NULL.
> 
> This code sample does skip the mandatory event_init, but event_del should be
> more cautious nevertheless.
> 

Why? You'd rather the code do an admittedly needless check millions,
possibly billions of times per process?

Windows mutexes don't support static initialization, so much worse
things--silent failures--might happen w/o explicit initializing. I don't use
libevent 2.0 so am unsure how locking is implemented, but that's just one
possible example.

Perhaps a better solution would be to use environment-specific extensions
such as __attribute__((constructor)) to do the initializing as a convenience
for the lazy amongst us. (And who isn't? ;) But even that is pushing it.
***********************************************************************
To unsubscribe, send an e-mail to majordomo@xxxxxxxxxxxxx with
unsubscribe libevent-users    in the body.