This is a discussion on Re: interface groups within the mailing.openbsd.tech forums, part of the OpenBSD category; --> * Artur Grabowski <art@blahonga.org> [2004-06-22 21:34]: > Henning Brauer <lists-openbsdtech@bsws.de> writes: > > > * Philipp Buehler <pb@openbsd.org> [2004-06-22 ...
| |||||||
| Register | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read |
| ||||
| * Artur Grabowski <art@blahonga.org> [2004-06-22 21:34]: > Henning Brauer <lists-openbsdtech@bsws.de> writes: > > > * Philipp Buehler <pb@openbsd.org> [2004-06-22 10:06]: > > > + TAILQ_FOREACH(ifgp, &ifp->if_groups, group_list) { > > > + TAILQ_REMOVE(&ifp->if_groups, ifgp, group_list); > > > > no... see manpage > > > > NOTES > > Trying to free a list in the following way is a common error: > > > > LIST_FOREACH(var, head, entry) > > free(var); > > free(head); > > > > Since var is free'd, the FOREACH() macro refers to a pointer that may > > have been reallocated already. Proper code needs a second variable. > > > > for (var = LIST_FIRST(head); var != LIST_END(head); var = nxt) { > > nxt = LIST_NEXT(var, entry); > > free(var); > > } > > LIST_INIT(head); /* to put the list back in order */ > > Stop giving bad advice. > > while ((foo = TAILQ_FIRST(..)) != NULL) { > TAILQ_REMOVE(foo ...); > free(foo); > } the manpage example is bad for draining the entire queue. the point however is that TAILQ_REMOVE in a TAILQ_FOREACH loop is going to bomb out. -- http://2suck.net/hhwl.html - http://www.bsws.de/ Unix is very simple, but it takes a genius to understand the simplicity. (Dennis Ritchie) |