Skip site navigation (1)Skip section navigation (2)
Date:      Tue, 21 Apr 2026 22:27:17 +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-main@FreeBSD.org
Subject:   git: 2434fcfd0dd0 - main - linuxkpi: Passing a size of zero to `krealloc()` frees the pointer
Message-ID:  <69e7f9c5.3878c.32c8cd42@gitrepo.freebsd.org>

index | next in thread | raw e-mail

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));


home | help

Want to link to this message? Use this
URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?69e7f9c5.3878c.32c8cd42>