* PROBLEM: memory leak in LIST_*, TAILQ_* man page
@ 2005-10-17 1:50 David Leppik
2005-10-17 2:18 ` [OT] " YOSHIFUJI Hideaki / 吉藤英明
0 siblings, 1 reply; 2+ messages in thread
From: David Leppik @ 2005-10-17 1:50 UTC (permalink / raw)
To: linux-kernel
My apologies if this is the wrong mailing list; I didn't find a better one.
The man page for TAILQ_REMOVE, etc. contains the following sample code:
while (head.tqh_first != NULL)
TAILQ_REMOVE(&head, head.tqh_first, entries);
I checked /usr/include/sys/queue.h and, sure enough, TAILQ_REMOVE
doesn't free
head.tqh_first. Nor should it-- this isn't Objective-C, after all. :-)
It should be something like:
while (head.tqh_first != NULL) {
np = head.tqh_first;
TAILQ_REMOVE(&head, np, entries);
free(np);
}
The same bug is repeated for all the data structures in this man page.
In this day and age of Java, C#, and Objective-C programmers, kids these
days
are less likely to remember to clean up after themselves. Therefore it was
particularly jarring to find this bug. Ten years ago I might have
laughed it
off. That's probably why it's been around for so long.
David
^ permalink raw reply [flat|nested] 2+ messages in thread
* [OT] Re: PROBLEM: memory leak in LIST_*, TAILQ_* man page
2005-10-17 1:50 PROBLEM: memory leak in LIST_*, TAILQ_* man page David Leppik
@ 2005-10-17 2:18 ` YOSHIFUJI Hideaki / 吉藤英明
0 siblings, 0 replies; 2+ messages in thread
From: YOSHIFUJI Hideaki / 吉藤英明 @ 2005-10-17 2:18 UTC (permalink / raw)
To: dleppik; +Cc: linux-kernel
In article <43530379.6040504@vocalabs.com> (at Sun, 16 Oct 2005 20:50:49 -0500), David Leppik <dleppik@vocalabs.com> says:
> The man page for TAILQ_REMOVE, etc. contains the following sample code:
>
> while (head.tqh_first != NULL)
> TAILQ_REMOVE(&head, head.tqh_first, entries);
>
> I checked /usr/include/sys/queue.h and, sure enough, TAILQ_REMOVE
> doesn't free
> head.tqh_first. Nor should it-- this isn't Objective-C, after all. :-)
>
> It should be something like:
>
> while (head.tqh_first != NULL) {
> np = head.tqh_first;
> TAILQ_REMOVE(&head, np, entries);
> free(np);
> }
Wrong. People do not always destroy the item removed
from the list, I think.
--yoshfuji
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2005-10-17 2:18 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2005-10-17 1:50 PROBLEM: memory leak in LIST_*, TAILQ_* man page David Leppik
2005-10-17 2:18 ` [OT] " YOSHIFUJI Hideaki / 吉藤英明
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox