This is sources Bugzilla
Bugzilla Version 2.17.5
Bugzilla Bug 1506
  Memory leak in sample code for LIST_, TAILQ_, and CIRCLEQ_REMOVE Last modified: 2005-10-23 01:03:44
     Query page      Enter new bug
Bug#: 1506   Hardware:   Reporter: David Leppik <dleppik@vocalabs.com>
Host: Target: Build:
Product:     Add CC:
Component:   Version:   CC:
Remove selected CCs
Status: RESOLVED   Priority:  
Resolution: DUPLICATE of bug 1481   Severity:  
Assigned To: Roland McGrath <roland@gnu.org>   Target Milestone:  
Flags: Requestee:
  backport ()
  examined ()
  testsuite ()
Summary:
Keywords:

Attachment Description Type Created Actions
Create a New Attachment (proposed patch, testcase, etc.) View All

Bug 1506 depends on: Show dependency tree
Show dependency graph
Bug 1506 blocks:

Additional Comments:


Leave as RESOLVED DUPLICATE
Reopen bug
Mark bug as VERIFIED

View Bug Activity   |   Format For Printing


Description:   Last confirmed: 0000-00-00 00:00 Opened: 2005-10-20 16:14
The man page describing sys/queue.h include sample code which is written in a
way that suggests that the *_REMOVE macros free memory.  For example:

 while (head.lh_first != NULL)           /* Delete. */
             LIST_REMOVE(head.lh_first, entries);

As a general purpose example of how to clear a LIST, this is misleading. 
Especially for all the kids today whose primary language is Java, C#, or
Objective-C.  (Sadly, I've become one of those kids :-) )

FreeBSD's current man page is more verbose:

                                             /* TailQ Deletion. */
> >      while (!TAILQ_EMPTY(&head)) {
> >              n1 = TAILQ_FIRST(&head);
> >              TAILQ_REMOVE(&head, n1, entries);
> >              free(n1);
> >      }
> >                                              /* Faster TailQ Deletion. */
> >      n1 = TAILQ_FIRST(&head);
> >      while (n1 != NULL) {
> >              n2 = TAILQ_NEXT(n1, entries);
> >              free(n1);
> >              n1 = n2;
> >      }
> >      TAILQ_INIT(&head);

(Thanks to John Baldwin for pointing the FreeBSD version out to me.)

------- Additional Comment #1 From Jakub Jelinek 2005-10-20 16:19 -------

*** This bug has been marked as a duplicate of 1481 ***

------- Additional Comment #2 From David Leppik 2005-10-20 16:43 -------
Subject: Re:  Memory leak in sample code for LIST_, TAILQ_,
 and CIRCLEQ_REMOVE

Should I create a bug that there is no documentation for
libc/misc/sys/queue.h, or is there someone else who mantains that code?

David


jakub at redhat dot com wrote:
> ------- Additional Comments From jakub at redhat dot com  2005-10-20 16:19 -------
> 
> 
> *** This bug has been marked as a duplicate of 1481 ***
> 



------- Additional Comment #3 From Roland McGrath 2005-10-23 01:03 -------
You can file an enhancement bug on the manual that the header and its macros
should be documented.  But the most effective thing will be to contribute some
documentation to the manual.  This is far from the highest priority for
improving the libc manual, and there is nearly no volunteer time available for
working on the manual.

     Query page      Enter new bug
Actions: New | Query | bug # | Reports | Requests   New Account | Log In