git: 2434fcfd0dd0 - main - linuxkpi: Passing a size of zero to `krealloc()` frees the pointer

From: Jean-Sébastien Pédron <dumbbell_at_FreeBSD.org>
Date: Tue, 21 Apr 2026 22:27:17 UTC
The branch main has been updated by dumbbell:

URL: https://cgit.FreeBSD.org/src/commit/?id=2434fcfd0dd07847a8518351b4525ec488f4d0bd

commit 2434fcfd0dd07847a8518351b4525ec488f4d0bd
Author:     Jean-Sébastien Pédron <dumbbell@FreeBSD.org>
AuthorDate: 2026-04-14 00:00:23 +0000
Commit:     Jean-Sébastien Pédron <dumbbell@FreeBSD.org>
CommitDate: 2026-04-21 22:18:26 +0000

    linuxkpi: Passing a size of zero to `krealloc()` frees the pointer
    
    This matches the API on Linux.
    
    Reviewed by:    bz
    Sponsored by:   The FreeBSD Foundation
    Differential Revision: https://reviews.freebsd.org/D56452
---
 sys/compat/linuxkpi/common/src/linux_slab.c | 5 +++++
 1 file changed, 5 insertions(+)

diff --git a/sys/compat/linuxkpi/common/src/linux_slab.c b/sys/compat/linuxkpi/common/src/linux_slab.c
index 96fe74dcd40d..a387e5c23ad3 100644
--- a/sys/compat/linuxkpi/common/src/linux_slab.c
+++ b/sys/compat/linuxkpi/common/src/linux_slab.c
@@ -250,6 +250,11 @@ lkpi_krealloc(const void *ptr, size_t size, gfp_t flags)
 	if (ptr == NULL)
 		return (kmalloc(size, flags));
 
+	if (size == 0) {
+		kfree(ptr);
+		return (ZERO_SIZE_PTR);
+	}
+
 	osize = ksize(ptr);
 	if (size <= osize)
 		return (__DECONST(void *, ptr));