| Message ID | 20251210000737.180797-12-sjg@u-boot.org |
|---|---|
| State | New |
| Headers |
Return-Path: <concept-bounces+u-boot-concept=u-boot.org@u-boot.org> X-Original-To: u-boot-concept@u-boot.org Delivered-To: u-boot-concept@u-boot.org DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=u-boot.org; s=default; t=1765325336; bh=/FV4Bd8j25n98/wkXJa0fYn84GD8Je+cOW5YJQkGGCw=; h=From:To:Date:In-Reply-To:References:CC:Subject:List-Id: List-Archive:List-Help:List-Owner:List-Post:List-Subscribe: List-Unsubscribe:From; b=pIYhat25mOPBBAtXfIME+2nkQHoOnz/fo+ZOxiww5sIlEKn7De6WeB+YNpH7IzPJR gbbmvX/DVARmzDdBE8dmI08mmOaeHdzeb8q8hYHXOAyoAag4Sok77u672xJJ5qQcJ/ dKVWrNVKLevdULMAA00CUBZoX/ZSIA6D2wstbpFBtzJ/FJhnWsLFTMZY/R24+c6M75 kcE8+CsggNxO+QieeEwIW59WPWTjaf9RRALiAOXpg7e+oRF0idwQY7arnmxN+2CsQA DLCdfxcXphjcGAi8qoJ+3Y8XWX3cLT5/IDzXpuxsNvDomoOYy/8KxMddQR8RQhB++a ueuMtipGLMNxA== Received: from localhost (localhost [127.0.0.1]) by mail.u-boot.org (Postfix) with ESMTP id 2140E689EA for <u-boot-concept@u-boot.org>; Tue, 9 Dec 2025 17:08:56 -0700 (MST) X-Virus-Scanned: Debian amavis at Received: from mail.u-boot.org ([127.0.0.1]) by localhost (mail.u-boot.org [127.0.0.1]) (amavis, port 10024) with ESMTP id R9pY6l5sKfBM for <u-boot-concept@u-boot.org>; Tue, 9 Dec 2025 17:08:56 -0700 (MST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=u-boot.org; s=default; t=1765325335; bh=/FV4Bd8j25n98/wkXJa0fYn84GD8Je+cOW5YJQkGGCw=; h=From:To:Date:In-Reply-To:References:CC:Subject:List-Id: List-Archive:List-Help:List-Owner:List-Post:List-Subscribe: List-Unsubscribe:From; b=YtNtPR6CDm1OTdF4IaPK5wjkwLqV/dZv0qpIxfwOCBtORdFyactCdVslbDORfb+Ue k2iLgUXGIsCbvRErE0lLOLpI8m/SA/lArUvJ9TUmaUBwVi7ih8ccahkDuTv5zY47V3 pAK2cNSuHnlqeGF4k1JPRYlHGc8+LRSt7H+GF24nwEN6QmK/nfIsCLp8aY2wUljfMo 1yQ5dJTRsAooX90AmdPNFDcDcBoMHGZ4okO0EhNHsJ0U05RbTXSzXGhqgX4bPjOblC wvHyWg26TMr0JE8eICwkZcChetfMJb6hEr0HQHxRxgg/8tKQ1eAdKfPe1kmH2OMQHW TtpTZDwLlhuBw== Received: from mail.u-boot.org (localhost [127.0.0.1]) by mail.u-boot.org (Postfix) with ESMTP id 7225A68A42 for <u-boot-concept@u-boot.org>; Tue, 9 Dec 2025 17:08:55 -0700 (MST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=u-boot.org; s=default; t=1765325331; bh=L6+L+iTRVQgT+g7gXuOfkO49+VE/GjuCFKiXPuyGjvs=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=h/WGtQHtmMsNY64CMtX9a//2xHn1zpqjTALu0hmJRM8EEzEWQ7XP1VSdQGxzs6hSl HTlN830RSHz7GIi4W08zZP18F+edt1AQR9rSPk9QcffkvkBavGN560iDvcy00EvVrZ Fc1J2tSUrlP1qcbsBbuw7GFRJg4m/Pg8tloj+M9oRU8Zoo84Kr9adkOKeIZpf7fIjE TtPtc/oRoEWIRniJ0yvC5+mQIaIFukUlrRN/JHBqKzyZrdJbHYvbd9rOAv7DRMK1O1 3zsn0plJBppvT2HPk3jGI/T4fa9utcRkLLTTUG9yv5k6ScxnLWi6vimIPSfmOeYi7m zFyl9PJSJL6nA== Received: from localhost (localhost [127.0.0.1]) by mail.u-boot.org (Postfix) with ESMTP id 0615868974; Tue, 9 Dec 2025 17:08:51 -0700 (MST) X-Virus-Scanned: Debian amavis at Received: from mail.u-boot.org ([127.0.0.1]) by localhost (mail.u-boot.org [127.0.0.1]) (amavis, port 10026) with ESMTP id n5ojw4bLyeBe; Tue, 9 Dec 2025 17:08:50 -0700 (MST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=u-boot.org; s=default; t=1765325325; bh=1DdkXiGfeffYvHLHR6SOmSHeoam8jVSpOg6dRJgCbPo=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=gX2HjQF6uWsaKShBSmKNngwQZAUUL9oSs7M3hrQXwm3VvdyvfXAJSSBsFfzVpzAuK lkKBB6KIeM/qcqj0w4wMF5LWNjEbu/OkX93RhEOD1SJNbewnthQq7kN1NcUevsh8el oEK/wfHll8y0w7V/H6fRdn2S3MYwKpPFWGIP42t/zGWSLR0gPlB0/QR4/Cm2dJEf13 1/qR7vp18IUw/a+Av3WByvIfvDUJF+uOeYw5HmGbMp1iFyS++fyRwxanY29C+RpFd6 cLQ7vfZVkjVFk0CwxXBMRbZf/+4KSOpjyiOo6bRiT2vcFZqcZfq0Xuufe6HgyaE7L8 lsJFTOyGLeTIQ== Received: from u-boot.org (unknown [73.34.74.121]) by mail.u-boot.org (Postfix) with ESMTPSA id 59F3768A22; Tue, 9 Dec 2025 17:08:45 -0700 (MST) From: Simon Glass <sjg@u-boot.org> To: U-Boot Concept <concept@u-boot.org> Date: Tue, 9 Dec 2025 17:07:02 -0700 Message-ID: <20251210000737.180797-12-sjg@u-boot.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20251210000737.180797-1-sjg@u-boot.org> References: <20251210000737.180797-1-sjg@u-boot.org> MIME-Version: 1.0 Message-ID-Hash: OCZHJKCNQUSQ6W73O4I7244ERHVCEWV2 X-Message-ID-Hash: OCZHJKCNQUSQ6W73O4I7244ERHVCEWV2 X-MailFrom: sjg@u-boot.org X-Mailman-Rule-Misses: dmarc-mitigation; no-senders; approved; loop; banned-address; emergency; member-moderation; nonmember-moderation; administrivia; implicit-dest; max-recipients; max-size; news-moderation; no-subject; digests; suspicious-header CC: Heinrich Schuchardt <xypron.glpk@gmx.de>, Simon Glass <simon.glass@canonical.com> X-Mailman-Version: 3.3.10 Precedence: list Subject: [Concept] [PATCH 11/35] malloc: Make mcheck respect REALLOC_ZERO_BYTES_FREES List-Id: Discussion and patches related to U-Boot Concept <concept.u-boot.org> Archived-At: <https://lists.u-boot.org/archives/list/concept@u-boot.org/message/OCZHJKCNQUSQ6W73O4I7244ERHVCEWV2/> List-Archive: <https://lists.u-boot.org/archives/list/concept@u-boot.org/> List-Help: <mailto:concept-request@u-boot.org?subject=help> List-Owner: <mailto:concept-owner@u-boot.org> List-Post: <mailto:concept@u-boot.org> List-Subscribe: <mailto:concept-join@u-boot.org> List-Unsubscribe: <mailto:concept-leave@u-boot.org> Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit |
| Series |
malloc: Add heap debugging commands and mcheck caller tracking
|
|
Commit Message
Simon Glass
Dec. 10, 2025, 12:07 a.m. UTC
From: Simon Glass <simon.glass@canonical.com> 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> --- common/dlmalloc.c | 2 ++ test/common/malloc.c | 2 +- 2 files changed, 3 insertions(+), 1 deletion(-)
diff --git a/common/dlmalloc.c b/common/dlmalloc.c index c1c9d8a8938..b46be1899f0 100644 --- a/common/dlmalloc.c +++ b/common/dlmalloc.c @@ -5923,11 +5923,13 @@ void dlfree(void *mem) { dlfree_impl(mcheck_free_prehook(mem)); } void *dlrealloc(void *oldmem, size_t bytes) { mcheck_pedantic_prehook(); +#ifdef REALLOC_ZERO_BYTES_FREES if (bytes == 0) { if (oldmem) dlfree(oldmem); return NULL; } +#endif if (oldmem == NULL) return dlmalloc(bytes); diff --git a/test/common/malloc.c b/test/common/malloc.c index b114267dd83..9fdc1789645 100644 --- a/test/common/malloc.c +++ b/test/common/malloc.c @@ -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)