Skip site navigation (1)Skip section navigation (2)
Date:      Wed, 29 Apr 2026 21:42:53 +0000
From:      Jean-=?utf-8?Q?S=C3=A9bast?==?utf-8?Q?ien P=C3=A9?=dron <dumbbell@FreeBSD.org>
To:        src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-branches@FreeBSD.org
Subject:   git: e07d29adeabf - stable/15 - linuxkpi: Passing a size of zero to `krealloc()` frees the pointer
Message-ID:  <69f27b5d.18c2b.6a914668@gitrepo.freebsd.org>

index | next in thread | raw e-mail

The branch stable/15 has been updated by dumbbell:

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

commit e07d29adeabf9dce7037455946ddc63c09745521
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-29 21:03:34 +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
    
    (cherry picked from commit 2434fcfd0dd07847a8518351b4525ec488f4d0bd)
---
 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));


home | help

Want to link to this message? Use this
URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?69f27b5d.18c2b.6a914668>