malloc: Make mcheck respect REALLOC_ZERO_BYTES_FREES

The mcheck wrapper for realloc() unconditionally frees memory and
returns NULL when size is 0. This differs from dlmalloc's default
behaviour which returns a minimum-sized allocation unless
REALLOC_ZERO_BYTES_FREES is defined.

Make the mcheck wrapper respect the same REALLOC_ZERO_BYTES_FREES
setting for consistent behavior with or without mcheck enabled.

Signed-off-by: Simon Glass <simon.glass@canonical.com>
This commit is contained in:
Simon Glass
2025-12-09 06:41:24 -07:00
parent f22cc09203
commit 95f10a6302
2 changed files with 3 additions and 1 deletions

View File

@@ -178,7 +178,7 @@ COMMON_TEST(common_test_realloc_null, 0);
/*
* Test realloc() with zero size
*
* Standard dlmalloc behavior (without REALLOC_ZERO_BYTES_FREES or mcheck):
* Standard dlmalloc behavior (without REALLOC_ZERO_BYTES_FREES):
* realloc(ptr, 0) returns a minimum-sized allocation.
*/
static int common_test_realloc_zero(struct unit_test_state *uts)