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
Unknown Object (File)
Tue, Sep 15, 9:29 AM
Unknown Object (File)
Sat, Sep 12, 3:45 PM
Unknown Object (File)
Sat, Sep 12, 2:22 PM
Unknown Object (File)
Tue, Sep 8, 1:07 AM
Unknown Object (File)
Sun, Sep 6, 5:10 AM
Unknown Object (File)
Fri, Sep 4, 7:10 PM
Unknown Object (File)
Thu, Sep 3, 3:08 AM
Unknown Object (File)
Tue, Aug 25, 10:26 PM
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