[Bug 291240] Mistake in hcreate(3) manpage

From: <bugzilla-noreply_at_freebsd.org>
Date: Wed, 26 Nov 2025 22:10:55 UTC
https://bugs.freebsd.org/bugzilla/show_bug.cgi?id=291240

            Bug ID: 291240
           Summary: Mistake in hcreate(3) manpage
           Product: Documentation
           Version: Latest
          Hardware: Any
                OS: Any
            Status: New
          Severity: Affects Many People
          Priority: ---
         Component: Manual Pages
          Assignee: bugs@FreeBSD.org
          Reporter: dacav@fastmail.com
                CC: doc@FreeBSD.org

Created attachment 265666
  --> https://bugs.freebsd.org/bugzilla/attachment.cgi?id=265666&action=edit
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".

-- 
You are receiving this mail because:
You are on the CC list for the bug.