From patchwork Thu Apr 16 02:29:30 2026 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Simon Glass X-Patchwork-Id: 2168 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=1776306654; bh=bRybQAR1cYTmpsXq5BtWQiE7tDmc31HxTddH0E6KeQg=; 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=m8JIR9jLJ4zbB6uBp6gM3tgSVa3xkIJ9TnLsEDURW9Gk8sZEvuitiidkVd1+fN7N9 4m81+XZjMbqmfdJGyYuVx1UkqFn6N/YOf/ACW95v4sidZH3U+ieqroOd4auZQJe7h/ ta6jgaG9kIV7MWizo4XdIHj4RpGST+76ikXKpALo= Received: from localhost (localhost [127.0.0.1]) by mail.u-boot.org (Postfix) with ESMTP id 045C76A4B5 for ; Wed, 15 Apr 2026 20:30:54 -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 i9R00VGL2F7r for ; Wed, 15 Apr 2026 20:30:53 -0600 (MDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=u-boot.org; s=default; t=1776306653; bh=bRybQAR1cYTmpsXq5BtWQiE7tDmc31HxTddH0E6KeQg=; 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=Ne6vmsDUU2JyPaJNWmal+dblTnyCreehUEqVRJNkMgdh/HgRk8gjOeKg2T+IYpdtG qOXtJTj47cIjlVYHVd96UtoyUVzMBeAPdA8r8IccFVng1XgWq8NlTZh/BZ/2nTG03n aDN14Bad2fonDA3ZT3tEnVhk/JfWaJMRiWwzSxi4= Received: from mail.u-boot.org (localhost [127.0.0.1]) by mail.u-boot.org (Postfix) with ESMTP id 21BDC6A4A7 for ; Wed, 15 Apr 2026 20:30:53 -0600 (MDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=u-boot.org; s=default; t=1776306650; bh=Nh77CLVbMvLA10DU3obvu0EGowhPKu5loB0RJnpghI0=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=i5hNbHdSwmMZbOXOlQxzJaQDjYh23jG5m2rAdoViqwsY8YCorLkfMxOHZG0E2eMiO 3iBg121wm82uNR+bNrLPMLX2VLK8LU7LViKd9rg7YK0mJfzymb6s047DG+yZyq8KSt tR6BA9bIHy0sjz0CQo5spqXXgs7ei59Vj3dSlGVA= Received: from localhost (localhost [127.0.0.1]) by mail.u-boot.org (Postfix) with ESMTP id 885D56A4A7; Wed, 15 Apr 2026 20:30:50 -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 SX3lvATsqdUq; Wed, 15 Apr 2026 20:30:50 -0600 (MDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=u-boot.org; s=default; t=1776306648; bh=4sScv2TksG3CQ1LKkWnlZqf4V7gPZhfvZGTR3y5NnUM=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=BHaObpogIVDc39bIfq+pvv39oiFwVUTmfnbHPnke+rtkR+O40hSlcygAzweoV5D7G 19sQW+r5NI3kIIF6ozkfN4oYgmfbutPnoxl73MlhSCli11vF/9opvzaYwstQBhrICB JpkJO0zxT3al7MXhoREUwyNXI0jkTxCqQTOH38X0= Received: from u-boot.org (unknown [73.34.74.121]) by mail.u-boot.org (Postfix) with ESMTPSA id D072D6A4B0; Wed, 15 Apr 2026 20:30:47 -0600 (MDT) From: Simon Glass To: U-Boot Concept Date: Wed, 15 Apr 2026 20:29:30 -0600 Message-ID: <20260416023021.626949-6-sjg@u-boot.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20260416023021.626949-1-sjg@u-boot.org> References: <20260416023021.626949-1-sjg@u-boot.org> MIME-Version: 1.0 Message-ID-Hash: V7RVAEEIBABLTAFWR3GZCS2MC4RDLMQ3 X-Message-ID-Hash: V7RVAEEIBABLTAFWR3GZCS2MC4RDLMQ3 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 05/33] malloc: Find aligned allocations using the registry 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 The leak-check printer reads the mcheck header from the start of each chunk, but for memalign() allocations the header is offset by aln_skip to satisfy alignment. Those chunks end up with no caller in the leak report, which hides up to several dozen leaks per test under a 'no-trace' bucket. Use find_mcheck_hdr_in_chunk(), which walks the registry and accounts for aln_skip, the same way malloc_dump_impl() already does. Signed-off-by: Simon Glass --- common/dlmalloc.c | 20 +++++++------------- 1 file changed, 7 insertions(+), 13 deletions(-) diff --git a/common/dlmalloc.c b/common/dlmalloc.c index 6d0bdc5b64e..6cc703f06fc 100644 --- a/common/dlmalloc.c +++ b/common/dlmalloc.c @@ -7833,21 +7833,15 @@ static void print_new_allocs(struct malloc_leak_snap *snap) #if CONFIG_IS_ENABLED(MCHECK_HEAP_PROTECTION) /* - * Read the caller directly from the mcheck - * header at the start of the chunk rather - * than searching the registry, which may - * have overflowed. Validate the canary first - * to avoid printing garbage from chunks - * allocated without mcheck (e.g. when mcheck - * was temporarily disabled). + * For memalign()ed chunks the header is + * offset by aln_skip, so use the registry- + * based lookup rather than assuming the + * header is at chunk2mem(q). */ - struct mcheck_hdr *hdr = mem; - int j; + struct mcheck_hdr *hdr; - for (j = 0; j < CANARY_DEPTH; j++) - if (hdr->canary.elems[j] != MAGICWORD) - break; - if (j == CANARY_DEPTH && hdr->caller[0]) + hdr = find_mcheck_hdr_in_chunk(mem, sz); + if (hdr && hdr->caller[0]) caller = hdr->caller; #endif printf(" %lx %zx %s\n", (ulong)mem, sz,