git: ca16e7a49204 - main - malloc: Fix realloc() for large allocations
- Go to: [ bottom of page ] [ top of archives ] [ this month ]
Date: Wed, 28 Oct 2026 13:07:20 UTC
The branch main has been updated by markj:
URL: https://cgit.FreeBSD.org/src/commit/?id=ca16e7a4920415bf9d09cf76bd2c3cda7447c098
commit ca16e7a4920415bf9d09cf76bd2c3cda7447c098
Author: Mark Johnston <markj@FreeBSD.org>
AuthorDate: 2026-10-22 16:41:04 +0000
Commit: Mark Johnston <markj@FreeBSD.org>
CommitDate: 2026-10-28 13:06:58 +0000
malloc: Fix realloc() for large allocations
min() truncates its parameters.
MFC after: 1 week
Sponsored by: The FreeBSD Foundation
---
sys/kern/kern_malloc.c | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/sys/kern/kern_malloc.c b/sys/kern/kern_malloc.c
index d2dd7ec5acee..6f3c3222daca 100644
--- a/sys/kern/kern_malloc.c
+++ b/sys/kern/kern_malloc.c
@@ -981,7 +981,7 @@ realloc(void *addr, size_t size, struct malloc_type *mtp, int flags)
uma_zone_t zone;
uma_slab_t slab;
#endif
- unsigned long alloc;
+ size_t alloc;
void *newaddr;
KASSERT(mtp->ks_version == M_VERSION,
@@ -1045,7 +1045,7 @@ realloc(void *addr, size_t size, struct malloc_type *mtp, int flags)
* valid before performing the copy.
*/
kasan_mark(addr, alloc, alloc, 0);
- bcopy(addr, newaddr, min(size, alloc));
+ bcopy(addr, newaddr, MIN(size, alloc));
free(addr, mtp);
return (newaddr);
}