Submit #1398 ยป hdestroy-3-Don-t-call-free-3-for-each-hash-key.patch
lib/libc/stdlib/hcreate.3 | ||
---|---|---|
29 | 29 |
.\" $FreeBSD: src/lib/libc/stdlib/hcreate.3,v 1.7 2008/07/06 17:03:37 danger Exp $ |
30 | 30 |
.\" $DragonFly: src/lib/libc/stdlib/hcreate.3,v 1.5 2006/05/26 19:39:37 swildner Exp $ |
31 | 31 |
.\" |
32 |
.Dd July 6, 2008
|
|
32 |
.Dd June 10, 2009
|
|
33 | 33 |
.Os |
34 | 34 |
.Dt HCREATE 3 |
35 | 35 |
.Sh NAME |
... | ... | |
75 | 75 |
After the call to |
76 | 76 |
.Fn hdestroy , |
77 | 77 |
the data can no longer be considered accessible. |
78 |
The |
|
79 |
.Fn hdestroy |
|
80 |
function calls |
|
81 |
.Xr free 3 |
|
82 |
for each comparison key in the search table |
|
83 |
but not the data item associated with the key. |
|
84 | 78 |
.Pp |
85 | 79 |
The |
86 | 80 |
.Fn hsearch |
... | ... | |
125 | 119 |
indicated by the return of a |
126 | 120 |
.Dv NULL |
127 | 121 |
pointer. |
128 |
.Pp |
|
129 |
The comparison key (passed to |
|
130 |
.Fn hsearch |
|
131 |
as |
|
132 |
.Fa item.key ) |
|
133 |
must be allocated using |
|
134 |
.Xr malloc 3 |
|
135 |
if |
|
136 |
.Fa action |
|
137 |
is |
|
138 |
.Dv ENTER |
|
139 |
and |
|
140 |
.Fn hdestroy |
|
141 |
is called. |
|
142 | 122 |
.Sh RETURN VALUES |
143 | 123 |
The |
144 | 124 |
.Fn hcreate |
lib/libc/stdlib/hcreate.c | ||
---|---|---|
136 | 136 |
while (!SLIST_EMPTY(&htable[idx])) { |
137 | 137 |
ie = SLIST_FIRST(&htable[idx]); |
138 | 138 |
SLIST_REMOVE_HEAD(&htable[idx], link); |
139 |
free(ie->ent.key); |
|
140 | 139 |
free(ie); |
141 | 140 |
} |
142 | 141 |
} |