This patch fix two problems with evport.c on Solaris:
1. The grow-function reallocates the ed_fds array, but ed_pending array may contain pointers to the elements in the ed_fds array. These pointers must be relocated to avoid using freed memory.
2. evport_dispatch does not handle a NULL-timval-pinter (no time-based events are active, wait for I/O).
--Trond
Index: evport.c =================================================================== --- evport.c (revision 428) +++ evport.c (working copy) @@ -240,8 +240,10 @@ grow(struct evport_data *epdp, int factor) { struct fd_info *tmp; + struct fd_info *old = epdp->ed_fds; int oldsize = epdp->ed_nevents; int newsize = factor * oldsize; + int ii; assert(factor > 1); check_evportop(epdp); @@ -252,6 +254,15 @@ epdp->ed_fds = tmp; memset((char*) (epdp->ed_fds + oldsize), 0, (newsize - oldsize)*sizeof(struct fd_info)); + + /* The ev_pending array contains pointers into the released array. */ + for (ii = 0; ii < EVENTS_PER_GETN; ++ii) { + if (epdp->ed_pending[ii] != 0) { + int offset = epdp->ed_pending[ii] - old; + epdp->ed_pending[ii] = epdp->ed_fds + offset; + } + } + epdp->ed_nevents = newsize; check_evportop(epdp); @@ -309,9 +320,16 @@ /* * We have to convert a struct timeval to a struct timespec - * (only difference is nanoseconds vs. microseconds) + * (only difference is nanoseconds vs. microseconds). If no time-based + * events are active, we should wait for I/O (and tv == NULL). */ - struct timespec ts = {tv->tv_sec, tv->tv_usec * 1000}; + struct timespec ts; + struct timespec *ts_p = NULL; + if (tv != NULL) { + ts.tv_sec = tv->tv_sec; + ts.tv_nsec = tv->tv_usec * 1000; + ts_p = &ts; + } /* * Before doing anything else, we need to reassociate the events we hit @@ -330,7 +348,7 @@ } if ((res = port_getn(epdp->ed_port, pevtlist, EVENTS_PER_GETN, - (unsigned int *) &nevents, &ts)) == -1) { + (unsigned int *) &nevents, ts_p)) == -1) { if (errno == EINTR) { evsignal_process(base); return (0);
_______________________________________________ Libevent-users mailing list Libevent-users@monkey.org http://monkey.org/mailman/listinfo/libevent-users