summaryrefslogtreecommitdiff
path: root/src/lib
diff options
context:
space:
mode:
authordaniel <>2026-08-10 22:02:41 +0000
committerdaniel <>2026-08-10 22:02:41 +0000
commit303993803a903836ebdee023fdaa9f772f2fcb05 (patch)
tree07f79a5b82b83f46e4874e53e3aecd0f82832606 /src/lib
parent3b6943ea7f6cc543fd185d87c30f0b8a50a15a55 (diff)
downloadopenbsd-303993803a903836ebdee023fdaa9f772f2fcb05.tar.gz
openbsd-303993803a903836ebdee023fdaa9f772f2fcb05.tar.bz2
openbsd-303993803a903836ebdee023fdaa9f772f2fcb05.zip
hdestroy(3): stop freeing key values
POSIX leaves ownership of ENTRY.key with the caller. Our current behaviour came from NetBSD when this code was imported in 2004. NetBSD and FreeBSD both stopped freeing key values in July 2014. NetBSD in commit fe0a1a6 and FreeBSD in commit e19f362. Remove the call to free(3) to align ourselves with NetBSD, FreeBSD and POSIX. Also adjust rsync for the change in semantics. Flagged by Sortix os-test. ok millert@, deraadt@
Diffstat (limited to 'src/lib')
-rw-r--r--src/lib/libc/stdlib/hcreate.346
-rw-r--r--src/lib/libc/stdlib/hcreate.c3
2 files changed, 3 insertions, 46 deletions
diff --git a/src/lib/libc/stdlib/hcreate.3 b/src/lib/libc/stdlib/hcreate.3
index 90bde1995f..48dffd4ff8 100644
--- a/src/lib/libc/stdlib/hcreate.3
+++ b/src/lib/libc/stdlib/hcreate.3
@@ -1,4 +1,4 @@
1.\" $OpenBSD: hcreate.3,v 1.8 2018/01/30 11:37:58 jmc Exp $ 1.\" $OpenBSD: hcreate.3,v 1.9 2026/08/10 22:02:41 daniel Exp $
2.\" $NetBSD: hcreate.3,v 1.8 2010/05/01 06:18:03 jruoho Exp $ 2.\" $NetBSD: hcreate.3,v 1.8 2010/05/01 06:18:03 jruoho Exp $
3.\" 3.\"
4.\" Copyright (c) 1999 The NetBSD Foundation, Inc. 4.\" Copyright (c) 1999 The NetBSD Foundation, Inc.
@@ -28,7 +28,7 @@
28.\" ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 28.\" ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
29.\" POSSIBILITY OF SUCH DAMAGE. 29.\" POSSIBILITY OF SUCH DAMAGE.
30.\" 30.\"
31.Dd $Mdocdate: January 30 2018 $ 31.Dd $Mdocdate: August 10 2026 $
32.Dt HCREATE 3 32.Dt HCREATE 3
33.Os 33.Os
34.Sh NAME 34.Sh NAME
@@ -127,30 +127,6 @@ key must not be modified during the lifetime of the hash table.
127Search the hash table without inserting 127Search the hash table without inserting
128.Fa item . 128.Fa item .
129.El 129.El
130.Pp
131Note that the comparison
132.Fa key
133must be allocated using
134.Xr malloc 3
135or
136.Xr calloc 3
137if action is
138.Dv ENTER
139and
140.Fn hdestroy
141will be called.
142This is because
143.Fn hdestroy
144will call
145.Xr free 3
146for each comparison
147.Fa key
148(but not
149.Fa data ) .
150Typically the comparison
151.Fa key
152is allocated by using
153.Xr strdup 3 .
154.Sh RETURN VALUES 130.Sh RETURN VALUES
155If successful, the 131If successful, the
156.Fn hcreate 132.Fn hcreate
@@ -189,7 +165,6 @@ Insufficient memory is available.
189.Sh SEE ALSO 165.Sh SEE ALSO
190.Xr bsearch 3 , 166.Xr bsearch 3 ,
191.Xr lsearch 3 , 167.Xr lsearch 3 ,
192.Xr malloc 3 ,
193.Xr strcmp 3 168.Xr strcmp 3
194.Sh STANDARDS 169.Sh STANDARDS
195The 170The
@@ -214,21 +189,4 @@ At least the following limitations can be mentioned:
214The interface permits the use of only one hash table at a time. 189The interface permits the use of only one hash table at a time.
215.It 190.It
216Individual hash table entries can be added, but not deleted. 191Individual hash table entries can be added, but not deleted.
217.It
218The standard is indecipherable about the
219internal memory usage of the functions,
220mentioning only that
221.Do
222.Fn hcreate
223and
224.Fn hsearch
225functions may use
226.Fn malloc
227to allocate space
228.Dc .
229This limits the portability of the functions,
230given that other implementations may not
231.Xr free 3
232the buffer pointed by
233.Fa key .
234.El 192.El
diff --git a/src/lib/libc/stdlib/hcreate.c b/src/lib/libc/stdlib/hcreate.c
index b31108a90e..ca6d8d16c4 100644
--- a/src/lib/libc/stdlib/hcreate.c
+++ b/src/lib/libc/stdlib/hcreate.c
@@ -1,4 +1,4 @@
1/* $OpenBSD: hcreate.c,v 1.7 2016/05/29 20:47:49 guenther Exp $ */ 1/* $OpenBSD: hcreate.c,v 1.8 2026/08/10 22:02:41 daniel Exp $ */
2/* $NetBSD: hcreate.c,v 1.5 2004/04/23 02:48:12 simonb Exp $ */ 2/* $NetBSD: hcreate.c,v 1.5 2004/04/23 02:48:12 simonb Exp $ */
3 3
4/* 4/*
@@ -142,7 +142,6 @@ hdestroy(void)
142 while (!SLIST_EMPTY(&htable[idx])) { 142 while (!SLIST_EMPTY(&htable[idx])) {
143 ie = SLIST_FIRST(&htable[idx]); 143 ie = SLIST_FIRST(&htable[idx]);
144 SLIST_REMOVE_HEAD(&htable[idx], link); 144 SLIST_REMOVE_HEAD(&htable[idx], link);
145 free(ie->ent.key);
146 free(ie); 145 free(ie);
147 } 146 }
148 } 147 }