mirror of
https://github.com/freebsd/freebsd-src.git
synced 2026-11-07 04:36:52 -10:00
mpool/mpool_get.c: Avoid clobbering 'errno' when handling 'pread' errors
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. Reviewed by: obiwac Differential Revision: https://reviews.freebsd.org/D55463 MFC after: 1 week
This commit is contained in:
1 parent
3023bb49e1
commit
bce0c14fe1
1 file changed
+4
@@ -214,10 +214,14 @@ mpool_get(MPOOL *mp, pgno_t pgno,
|
||||
/* Read in the contents. */
|
||||
off = mp->pagesize * pgno;
|
||||
if ((nr = pread(mp->fd, bp->page, mp->pagesize, off)) != (ssize_t)mp->pagesize) {
|
||||
int serrno;
|
||||
|
||||
switch (nr) {
|
||||
case -1:
|
||||
/* errno is set for us by pread(). */
|
||||
serrno = errno;
|
||||
free(bp);
|
||||
errno = serrno;
|
||||
mp->curcache--;
|
||||
return (NULL);
|
||||
case 0:
|
||||
|
||||
Reference in new issue
Block a user