Date: Sun, 16 Oct 2005 21:50:12 GMT From: David Leppik <dleppik@vocalabs.com> To: freebsd-gnats-submit@FreeBSD.org Subject: docs/87548: LIST_*, TAILQ_* man pages include memory leak in sample code Message-ID: <200510162150.j9GLoCAt040327@www.freebsd.org> Resent-Message-ID: <200510162200.j9GM0RQK008697@freefall.freebsd.org>
next in thread | raw e-mail | index | archive | help
>Number: 87548 >Category: docs >Synopsis: LIST_*, TAILQ_* man pages include memory leak in sample code >Confidential: no >Severity: non-critical >Priority: low >Responsible: freebsd-doc >State: open >Quarter: >Keywords: >Date-Required: >Class: doc-bug >Submitter-Id: current-users >Arrival-Date: Sun Oct 16 22:00:27 GMT 2005 >Closed-Date: >Last-Modified: >Originator: David Leppik >Release: None (old BSD code--see below) >Organization: Vocal Laboratories >Environment: >Description: I've seen this on Mac OS X and Linux, so this probably affects FreeBSD as well. The man page for TAILQ_INSERT, TAILQ_REMOVE, etc. have the following sample code: while (head.tqh_first != NULL) TAILQ_REMOVE(&head, head.tqh_first, entries); I was so shocked that I checked queue.h and sure enough, TAILQ_REMOVE does not deallocate the queue entry (nor should it.) The same is true for the other structures mentioned in this man page. >How-To-Repeat: >Fix: I'm just a lowly Java programmer, but I think the fix is: while (head.tqh_first != NULL) { np = head.tqh_first; TAILQ_REMOVE(&head, np, entries); free(np); } >Release-Note: >Audit-Trail: >Unformatted:
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?200510162150.j9GLoCAt040327>