[vlc-devel] [vlc-commits] dbus: allocate pollfd array on the stack

mirsal mirsal at mirsal.fr
Mon Aug 8 12:27:09 CEST 2011


On Mon, 2011-08-08 at 08:30 +0200, Rémi Denis-Courmont wrote:
> On Mon,  8 Aug 2011 02:08:43 +0200 (CEST), git at videolan.org (Rafaël Carré)
> wrote:
> >          int i_watches = vlc_array_count( p_sys->p_watches );
> > -        struct pollfd *p_fds = calloc( i_watches, sizeof( struct pollfd
> )
> > );
> > +        struct pollfd fds[i_watches];
> > +        memset(fds, 0, sizeof fds);
> 
> Contrary to popular belief, pollfd do not need to be memset(). poll() only
> reads the fd and events fields, which will not normally be zero, and writes
> the revents field. 

Yes that makes a lot of sense, though in that particular case it will
break if we only remove the call to memset as the events fields are
currently populated that way (which might be very stupid):

        if( i_flags & DBUS_WATCH_READABLE )
            p_fds[i_fds].events |= POLLIN | POLLPRI;

        if( i_flags & DBUS_WATCH_WRITABLE )
            p_fds[i_fds].events |= POLLOUT;

Do you think I should remove the call to memset and properly initialize
the event fields just before populating them ?

Thanks :)

-- 
mirsal
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 490 bytes
Desc: This is a digitally signed message part
URL: <http://mailman.videolan.org/pipermail/vlc-devel/attachments/20110808/01b81a96/attachment.sig>


More information about the vlc-devel mailing list