According to the current POSIX standard, errno must be saved across the free() call, it is also recommendation of the future standard version (Resolved state): http://austingroupbugs.net/view.php?id=385#c713 "However, earlier versions of this standard did not require this, and the same example had to be written as: // buf was obtained by malloc(buflen) ret = write(fd, buf, buflen); if (ret < 0) { int save = errno; free(buf); errno = save; return ret; } " "earlier" here is current version. Please read whole problem description and discussion at this URL too. When I attempt to commit that recommended "save errno across free()" way in realpath.c I got enough feedback showing that many members tend to avoid mass code change needed for current standard strict compliance and prefer to track unpublished standard instead, where free() must not modify errno. -current and -stable free() versions may issue some syscalls which may modify errno (depends on debug flags, KTR, etc), so I suggest to directly save and restore errno in the free() to avoid any possible modifications. Fix: + serrno = errno; + UTRACE(ptr, 0, 0); if (ptr != NULL) { assert(malloc_initialized); idalloc(ptr); } + errno = serrno; } /*--kEl2jvLSY3mvFiM9EyoGOZgtdgZS47KvGGcgk53D6HzyaFpB Content-Type: text/plain; name="file.diff" Content-Transfer-Encoding: 7bit Content-Disposition: attachment; filename="file.diff" Index: malloc.c =================================================================== --- malloc.c (revision 236135) +++ malloc.c (working copy) @@ -6146,13 +6146,17 @@ void free(void *ptr) { + int serrno;
Responsible Changed From-To: freebsd-standards->jasone Reassign to our malloc() maintainer
batch change of PRs untouched in 2018 marked "in progress" back to open.
Right now, FreeBSD uses jemalloc(http://jemalloc.net) for memory allocating. The latest release came out in 2019 and it was reflected to FreeBSD in 2020, but the development is still ongoing. This bug report should be closed, and if there is any problem regarding this, this should be reported to jemalloc repository(https://github.com/jemalloc/jemalloc)
^Triage: * summary, priority, severity, keywords * add former assignee standards@ to the CC list. (In reply to Minsoo Choo from 2002 comment #3) jason@ would you like to close this report?
> jason@ Sorry, jasone@