From 303993803a903836ebdee023fdaa9f772f2fcb05 Mon Sep 17 00:00:00 2001 From: daniel <> Date: Mon, 10 Aug 2026 22:02:41 +0000 Subject: 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@ --- src/lib/libc/stdlib/hcreate.3 | 46 ++----------------------------------------- src/lib/libc/stdlib/hcreate.c | 3 +-- 2 files changed, 3 insertions(+), 46 deletions(-) (limited to 'src/lib/libc/stdlib') 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 @@ -.\" $OpenBSD: hcreate.3,v 1.8 2018/01/30 11:37:58 jmc Exp $ +.\" $OpenBSD: hcreate.3,v 1.9 2026/08/10 22:02:41 daniel Exp $ .\" $NetBSD: hcreate.3,v 1.8 2010/05/01 06:18:03 jruoho Exp $ .\" .\" Copyright (c) 1999 The NetBSD Foundation, Inc. @@ -28,7 +28,7 @@ .\" ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE .\" POSSIBILITY OF SUCH DAMAGE. .\" -.Dd $Mdocdate: January 30 2018 $ +.Dd $Mdocdate: August 10 2026 $ .Dt HCREATE 3 .Os .Sh NAME @@ -127,30 +127,6 @@ key must not be modified during the lifetime of the hash table. Search the hash table without inserting .Fa item . .El -.Pp -Note that the comparison -.Fa key -must be allocated using -.Xr malloc 3 -or -.Xr calloc 3 -if action is -.Dv ENTER -and -.Fn hdestroy -will be called. -This is because -.Fn hdestroy -will call -.Xr free 3 -for each comparison -.Fa key -(but not -.Fa data ) . -Typically the comparison -.Fa key -is allocated by using -.Xr strdup 3 . .Sh RETURN VALUES If successful, the .Fn hcreate @@ -189,7 +165,6 @@ Insufficient memory is available. .Sh SEE ALSO .Xr bsearch 3 , .Xr lsearch 3 , -.Xr malloc 3 , .Xr strcmp 3 .Sh STANDARDS The @@ -214,21 +189,4 @@ At least the following limitations can be mentioned: The interface permits the use of only one hash table at a time. .It Individual hash table entries can be added, but not deleted. -.It -The standard is indecipherable about the -internal memory usage of the functions, -mentioning only that -.Do -.Fn hcreate -and -.Fn hsearch -functions may use -.Fn malloc -to allocate space -.Dc . -This limits the portability of the functions, -given that other implementations may not -.Xr free 3 -the buffer pointed by -.Fa key . .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 @@ -/* $OpenBSD: hcreate.c,v 1.7 2016/05/29 20:47:49 guenther Exp $ */ +/* $OpenBSD: hcreate.c,v 1.8 2026/08/10 22:02:41 daniel Exp $ */ /* $NetBSD: hcreate.c,v 1.5 2004/04/23 02:48:12 simonb Exp $ */ /* @@ -142,7 +142,6 @@ hdestroy(void) while (!SLIST_EMPTY(&htable[idx])) { ie = SLIST_FIRST(&htable[idx]); SLIST_REMOVE_HEAD(&htable[idx], link); - free(ie->ent.key); free(ie); } } -- cgit v1.2.3-55-g6feb