On Thu, Aug 2, 2012 at 1:58 PM, Pete Batard <p...@akeo.ie> wrote:
>
> > Setting next and prev to NULL in list_del() caused a crash in
> > usbi_cond_destroy() in threads_windows.c (next was used after calling
> > list_del). Using list_for_each_entry_safe fixed it and cleaned up the
> code.
> >
> > int usbi_cond_destroy(usbi_cond_t *cond) {
> > // This assumes no one is using this anymore. The check MAY NOT BE
> > safe.
> > struct usbi_cond_perthread *pos, *next_pos = NULL;
> > if(!cond) return ((errno=EINVAL));
> > if(!list_empty(&cond->waiters)) return ((errno=EBUSY )); // (!see
> > above!)
> > list_for_each_entry_safe(pos, next_pos, &cond->not_waiting, list,
> > struct usbi_cond_perthread) {
> > CloseHandle(pos->event);
> > list_del(&pos->list);
> > free(pos);
> > }
> >
> > return 0;
> > }
>
>
> Interesting. Do you know in which call next was being used?
> Still, if we apply the nulling of prev/next, we're likely to get reports
> from Windows users with the same issue, that we can address then.
>
list_for_each_entry() uses next as it steps through the list.
list_for_each_entry_safe() avoids the problem by getting and saving the
next pointer in a temporary before the loop body.
Orin.
------------------------------------------------------------------------------
Live Security Virtual Conference
Exclusive live event will cover all the ways today's security and
threat landscape has changed and how IT managers can respond. Discussions
will include endpoint security, mobile security and the latest in malware
threats. http://www.accelacomm.com/jaw/sfrnl04242012/114/50122263/
_______________________________________________
libusbx-devel mailing list
libusbx-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/libusbx-devel