summaryrefslogtreecommitdiff
path: root/share/man
diff options
context:
space:
mode:
authorNiels Provos <provos@cvs.openbsd.org>2002-04-22 16:41:55 +0000
committerNiels Provos <provos@cvs.openbsd.org>2002-04-22 16:41:55 +0000
commit288f5d5d4b99badf7e3e91cf99758afafe4c0ecc (patch)
tree26b3db4b17544e018c34ffba83045bd69e73615c /share/man
parent6bd2008fa98cf973716c21f2db6d7fadead7186f (diff)
fix example showing how to properly free a tree; pointed out by dugsong@
Diffstat (limited to 'share/man')
-rw-r--r--share/man/man3/tree.37
1 files changed, 5 insertions, 2 deletions
diff --git a/share/man/man3/tree.3 b/share/man/man3/tree.3
index 4683a2a9653..897a405444b 100644
--- a/share/man/man3/tree.3
+++ b/share/man/man3/tree.3
@@ -1,4 +1,4 @@
-.\" $OpenBSD: tree.3,v 1.4 2002/04/08 21:07:54 dugsong Exp $
+.\" $OpenBSD: tree.3,v 1.5 2002/04/22 16:41:54 provos Exp $
.\"/*
.\" * Copyright 2002 Niels Provos <provos@citi.umich.edu>
.\" * All rights reserved.
@@ -412,8 +412,10 @@ macro should be used to check whether a splay tree is empty.
.Sh NOTES
Trying to free a tree in the following way is a common error:
.Bd -literal -offset indent
-SPLAY_FOREACH(var, NAME, head)
+SPLAY_FOREACH(var, NAME, head) {
+ SPLAY_REMOVE(NAME, head, var);
free(var);
+}
free(head);
.Ed
.Pp
@@ -426,6 +428,7 @@ Proper code needs a second variable.
.Bd -literal -offset indent
for (var = SPLAY_MIN(NAME, head); var != NULL; var = nxt) {
nxt = SPLAY_NEXT(NAME, head, var);
+ SPLAY_REMOVE(NAME, head, var);
free(var);
}
.Ed