Page MenuHomeFreeBSD

mpool/mpool_get.c: Avoid clobbering 'errno' when handling 'pread' errors
ClosedPublic

Authored by bnovkov on Feb 23 2026, 3:51 PM.
Tags
None
Referenced Files
F159292190: D55463.id172519.diff
Fri, Jun 12, 12:01 PM
Unknown Object (File)
Wed, Jun 10, 7:22 AM
Unknown Object (File)
Wed, Jun 10, 2:04 AM
Unknown Object (File)
Tue, Jun 9, 11:41 AM
Unknown Object (File)
Tue, Jun 9, 5:35 AM
Unknown Object (File)
Sun, Jun 7, 12:17 AM
Unknown Object (File)
Sat, May 23, 7:55 PM
Unknown Object (File)
Thu, May 21, 11:03 AM
Subscribers

Details

Summary

POSIX.1-2024 states that the 'free' function "shall not modify errno if
ptr is a null pointer or a pointer previously returned as if by malloc()
and not yet deallocated". However this is a fairly recent addition
and non-compliant allocators might still clobber 'errno', causing
'mpool_get' to return the wrong error code. Fix this by saving
and restoring 'errno' after calling 'free'.

Sponsored by: Klara, Inc.

Diff Detail

Repository
rG FreeBSD src repository
Lint
Lint Not Applicable
Unit
Tests Not Applicable

Event Timeline

obiwac added inline comments.
lib/libc/db/mpool/mpool.c
236–241

here there's not really a point in saving errno if we're going to set it to EINVAL anyways

Remove redundant errno save

bnovkov added inline comments.
lib/libc/db/mpool/mpool.c
236–241

whoops, pattern-matched a bit too greedily, thanks!

This revision is now accepted and ready to land.Feb 23 2026, 5:59 PM