From patchwork Sat Mar 14 23:16:02 2026 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Simon Glass X-Patchwork-Id: 1983 Return-Path: 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=1773530269; bh=WUwUJFnFl860Aqb5NeR3Qt6tL9MrP7npRdaqPKbalGQ=; 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=F5MZCDttEuwuZr8TLnEMQlmJZiSDFePdD2ZeHLXlbanZ7VbRsSInPN1L3yJtQHhHc 46hqv5Kq594wR0EIBaqR/HTDy+LtX2zxiwWcng9MDCj5RZPBBn7AsICTKgGDRJ6sG5 A4rlLto1Zn9TVtHBu2KMc7oCP+mLI3a4x0ff+7JlvHKfsACryDM1MktbfKO8uJ/H5I YwDGA2YnnFhlBVjnAsmQIyA+VRgs7m38535qbCdtKncBsCfdaJN4P8a4RxBXf1QMLV LG9qaGGFk3WU6AYxOSTulhsSpio9HO8ilKpIHpA0Eb5W2bcJ6MkJXNeYxGI/UwC69r GcVpTLfEzSeNg== Received: from localhost (localhost [127.0.0.1]) by mail.u-boot.org (Postfix) with ESMTP id E026E6A059 for ; Sat, 14 Mar 2026 17:17:49 -0600 (MDT) 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 P0spwjrlwDmi for ; Sat, 14 Mar 2026 17:17:49 -0600 (MDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=u-boot.org; s=default; t=1773530266; bh=WUwUJFnFl860Aqb5NeR3Qt6tL9MrP7npRdaqPKbalGQ=; 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=esAOTwFe7pGr5Sy61Xvi1rAl0pocFQQU7+vqg6UEZX/+20YdidusUSiwKNCGNBzG/ 0w75RGszqr/SEuGSiWsMNhse/LLxvWRwAKST2Ox2OEwwFzJZ+WMLMLWr2M31Az7GOc xg3cJ0XuAQ3UGw8NH7Fy2ZNUg0XzQJmJ4ZSAzoILh49qXKNlHlZOjMjlkv47PCniDb VDx3gbHJ/o+WAaiSP4OO0y2qgq7wran5rvSeACCS0/o9JSJXPQk8YlOZlLSbDgsYQt xpVpzpH+nNS20f0q7IGjlaPuWQYuVU18hZ20hBqYXdtpSlBAP8205oeJnzcJ8P7raZ yb7UTZM1PBJJw== Received: from mail.u-boot.org (localhost [127.0.0.1]) by mail.u-boot.org (Postfix) with ESMTP id 80A896A04C for ; Sat, 14 Mar 2026 17:17:46 -0600 (MDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=u-boot.org; s=default; t=1773530264; bh=+ZVsaOwnTvv6FY5f/RZoYmeJAtdhYGtdqjRrVaYmFJU=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=JiY+2fn1N2BOOLpns9OmvNFT+wjiU3jBH6+whB7bfUPT/XX+0uCF6aZ93NyxcgsKB fCockvgaHpRcVIYoYZ/VC1ICISJFlCVptW9RlrJ4mDaj+OoNO1SX+HkP9gH1nCApna Tbl8cB3AzZOAaQw5ECkmBE48PbQ96z5PI7KRk5RqKOjkOWkfR7cmwRlHgNs/5S0Ico plhH1W3dZ+R7zwJoo/nM1SHpLxQX0AKz3+w5gfOKonMf9sbNdUMBC+ZfL8NFGYdOzb +8zPqdeLRVRqwj5Oi2uYLTW2mVHEuI3uMBeUzqLHuK2Ns6f+A1mzuDKwRAzhx8iUjn 68zzeVKTSD1KQ== Received: from localhost (localhost [127.0.0.1]) by mail.u-boot.org (Postfix) with ESMTP id 167126A03C; Sat, 14 Mar 2026 17:17:44 -0600 (MDT) 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 rzFpQtnNvvlm; Sat, 14 Mar 2026 17:17:44 -0600 (MDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=u-boot.org; s=default; t=1773530260; bh=wF8Yo77ENnvNjRk7o1+hHkK3+ErusmGFNisE/FiShvI=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=bcfys1Q+TAMLiMc5HDrVia3R+4mPWnW6XNe2o+s+M+n8hRJE2iapl8Ix9Ite0f9Li OGMseBVzBkET22EguJ6/PPRRyLlvqJGo09KkIsPalG1S/php6Ui4g0maBkUVRF6bSc V7xh/OBkIETNJVaP6uE2AOeVUHCpoL7oYDHW4KtykHgkAfnMoSVSFBizKQrowTWC7Y 5CcvlsbHs+Wa0EMt8JkNQrTuF1WaxOHUK4QDWjULv4UNEy/zeho3Awe3E7f3zRgOgZ J5w+n33kOSTFUwVAonJerdPb0kyQGEl5oIlXqzoLNIHMctcWVFbVC0ZAmFToSGPDhm Zd9oC1mKf6+Zw== Received: from u-boot.org (unknown [73.34.74.121]) by mail.u-boot.org (Postfix) with ESMTPSA id 978EA69ECF; Sat, 14 Mar 2026 17:17:40 -0600 (MDT) From: Simon Glass To: U-Boot Concept Date: Sat, 14 Mar 2026 17:16:02 -0600 Message-ID: <20260314231618.338113-12-sjg@u-boot.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20260314231618.338113-1-sjg@u-boot.org> References: <20260314231618.338113-1-sjg@u-boot.org> MIME-Version: 1.0 Message-ID-Hash: ILZOIRWEYADMIIGMTUAXC77LM6CSPDCB X-Message-ID-Hash: ILZOIRWEYADMIIGMTUAXC77LM6CSPDCB 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: Simon Glass X-Mailman-Version: 3.3.10 Precedence: list Subject: [Concept] [PATCH 11/19] test: common: Fix memory leak in malloc_fill_pool test List-Id: Discussion and patches related to U-Boot Concept Archived-At: List-Archive: List-Help: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: From: Simon Glass When common_test_malloc_fill_pool() fills the heap and then fails an assertion (e.g. because earlier tests leaked memory, reducing the available pool), it returns early without freeing the allocations. This leaks ~120 MB — the entire malloc pool — causing all subsequent tests that need malloc to fail. Free all allocations before checking the peak, so that a test failure does not leak the entire pool and break all subsequent tests. Signed-off-by: Simon Glass --- test/common/malloc.c | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) -- 2.43.0 diff --git a/test/common/malloc.c b/test/common/malloc.c index af1a7326272..c4764a51f6b 100644 --- a/test/common/malloc.c +++ b/test/common/malloc.c @@ -616,18 +616,24 @@ static int common_test_malloc_fill_pool(struct unit_test_state *uts) ptr_table_size); /* - * Should have allocated most of the pool - if we can't allocate - * 1MB, then at most 1MB is available, so we must have allocated - * at least (pool_size - 1MB) + * Should have allocated most of the pool - if we can't allocate 1MB, + * then at most 1MB is available, so we must have allocated at least + * (pool_size - 1MB). Save the peak before freeing so an assertion + * failure does not leak the entire pool. */ ut_assert(count > 0); ut_assert(count < ptr_table_size / sizeof(void *)); - ut_assert(get_alloced_size() >= TOTAL_MALLOC_LEN - SZ_1M); + alloc_size = get_alloced_size(); - /* Free all allocations */ + /* + * Free all allocations before checking the peak, so that a failure does + * not leak the entire pool and break later tests + */ for (i = 0; i < count; i++) free(ptrs[i]); + ut_assert(alloc_size >= TOTAL_MALLOC_LEN - SZ_1M); + /* Should be back to starting state */ ut_asserteq(before, get_alloced_size());