Bug 291240 - Mistake in hcreate(3) manpage
Summary: Mistake in hcreate(3) manpage
Status: New
Alias: None
Product: Documentation
Classification: Unclassified
Component: Manual Pages (show other bugs)
Version: Latest
Hardware: Any Any
: --- Affects Many People
Assignee: freebsd-bugs (Nobody)
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2025-11-26 22:10 UTC by dacav
Modified: 2025-12-02 18:33 UTC (History)
3 users (show)

See Also:


Attachments
Shell session: trivial example + valgrind (1.41 KB, text/plain)
2025-11-26 22:10 UTC, dacav
no flags Details

Note You need to log in before you can comment on or make changes to this bug.
Description dacav 2025-11-26 22:10:55 UTC
Created attachment 265666 [details]
Shell session: trivial example + valgrind

The manpage claims that:

> The hdestroy() function calls free(3) for each comparison key in
> the search table but not the data item associated with the key.

This seems incorrect.

The implementation frees the table but not the table items:
https://cgit.freebsd.org/src/tree/lib/libc/stdlib/hdestroy_r.c
See also attached proof.

I think the problem is in the manpage because current implementation behaves correctly:

- POSIX is not specific about it in the function description, but it provides an example where the caller holds ownership of the keys: https://pubs.opengroup.org/onlinepubs/9699919799/functions/hcreate.html

- The GNU manpage hsearch(3) claims that: "The hdestroy() and hdestroy_r() functions do not free the buffers pointed to by the key and data elements of the hash table entries".