| Message ID | 20251201170529.3237986-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=1764608909; bh=2TL7pDb2C2AZUmWu+Gyckrb8wG35+7gPeSnPkcFvlwE=; 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=UPj+pF7EbWM5Xtz2vxqUJN2JHaYlfEGWyQK/B2tox2W7zjnjY6zW/+bQDVFGmWj2c xR9hpbA8tIBsAkj9hEcYlxVJb0+7aqmgOD64DLmfIOos0Fz3wOj06ojYNfoi9jlpPH ItflNOSFzAIZbmCSxpELO1zvEKakGvL4g1qyhndfn+bvdXwqIdhOd3Vt9cKY1tSUpn DxPme4lPSl3FTlAGhxqrzbwoeXec43oSAmMpoLfvWoUlh6Z0algyDiKf5KxKjXrJ1C VY+SurJjRzZXEtMnZvq1BMtFxURPf4Qj+Kvf9Jk4mcgBNCI9oBkTmfHLzZvcpLdpYJ iQ5ZxXdRS5frw== Received: from localhost (localhost [127.0.0.1]) by mail.u-boot.org (Postfix) with ESMTP id 1F81E688B6 for <u-boot-concept@u-boot.org>; Mon, 1 Dec 2025 10:08:29 -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 TezkDSJW_BIQ for <u-boot-concept@u-boot.org>; Mon, 1 Dec 2025 10:08:29 -0700 (MST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=u-boot.org; s=default; t=1764608908; bh=2TL7pDb2C2AZUmWu+Gyckrb8wG35+7gPeSnPkcFvlwE=; 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=w1LbtTARngoNyj1ryakcWFRv9C9z/rZI7FOa4ogC/LHb6JMf8N0Py1WLBDdiTaHGH Tq8KqL7DZPP2XZq7OwIWXLQ2BpO7J6y4Zhfiaf+JIeW+zbiZDDaqgdriC3WT08sx5W cb40aeQhBkO7NWK/mEH7XbIi20dx691LRqv1ogI/GpzI88tsxfFlv4plVK7zfm1vNW nLhRzs7FPml5GR9a0bp1czbwBsA+FtqrFPjt1qBBWl4RYVAa3lC6cr11ZyugiriKzD LK09xMueieHy2Ox69XpWBiOkddqmXUyXmWI0NPZ4DbxYuFO3NKh6cbjhg0NX4ly6Ku YtDrwZS1/5Wdg== Received: from mail.u-boot.org (localhost [127.0.0.1]) by mail.u-boot.org (Postfix) with ESMTP id E596A688D3 for <u-boot-concept@u-boot.org>; Mon, 1 Dec 2025 10:08:28 -0700 (MST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=u-boot.org; s=default; t=1764608905; bh=at/cNDf1wKF2uUMEn5XsCgf/0H9z3WctyRW6GvRlM7E=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=t96hbuPc99Ao+ShsG+o1TBLJov2LdN+xTyPVi2X7vyM5lANXngqQFZxFo7M0JDphi hhjrw7L2vdzjl1owoaCzbO0AB50E3v7nmHI0E2zm4ym6TPWNGXkR8D3Zi3HYh8LqvK nLv9e77gdInGEPQ/tr026F05KK+W7pc4rh8GZGcx/9MRSRUuocTs83IjTDmUzry4lN hsI7pQP15smi/0C8i9c9tIG70gyavuLHD6dHIqpSHlI3eHMlEf9pzXuZZxRM7OhMaT 7Y51DILdirA7OxTlPpHtzwAwcXtZfg3uF6YLhsm8JTaSRtdCed/80biLeQtjQKP5KT w7OPMS8uw7/iw== Received: from localhost (localhost [127.0.0.1]) by mail.u-boot.org (Postfix) with ESMTP id A25E46881A; Mon, 1 Dec 2025 10:08:25 -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 DHTnIJ7lh2H1; Mon, 1 Dec 2025 10:08:25 -0700 (MST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=u-boot.org; s=default; t=1764608901; bh=wtLUuptUL2FTUzEdOMmh81YFLSpRJAkkZgoP7RQeqFo=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=FuwXQOMlX9DuTEU+ralyEf7MI4FADINWmnX8X+7NI8G2HBmog3eHxNIxcTkSlTZSx 5pjK3c9LFmM4Oxs5t6BlEzp5h4o8YaVAl8pTa9tXP/YSSnbu33e9ipoysJFkpLP5N3 bYn3gTPtsdD4CuGySw4WXEvp7K1CXxQ/BvTVcKT+42LCFP1Bf9+tqvrPnU6CVcq2ok Y6F+0Xnc0HZgykyFGJcJbiTntCRP6qgjTOuoYJz9uaijOyh8tVRrg0HilB7oLHyFhT Yg/T2KbHKxg2m+EdM/xSYyzhw85X4o7EWXIyCuDBCetYgVtEStjcfz07JHfMAgA8/I Lx9q+0cHeSs4A== Received: from u-boot.org (unknown [73.34.74.121]) by mail.u-boot.org (Postfix) with ESMTPSA id 2A355688D3; Mon, 1 Dec 2025 10:08:21 -0700 (MST) From: Simon Glass <sjg@u-boot.org> To: U-Boot Concept <concept@u-boot.org> Date: Mon, 1 Dec 2025 10:04:50 -0700 Message-ID: <20251201170529.3237986-12-sjg@u-boot.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20251201170529.3237986-1-sjg@u-boot.org> References: <20251201170529.3237986-1-sjg@u-boot.org> MIME-Version: 1.0 Message-ID-Hash: OKQIBWIODW2QOMQ7EUO7V32UPMS2J5Y7 X-Message-ID-Hash: OKQIBWIODW2QOMQ7EUO7V32UPMS2J5Y7 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/37] malloc: return NULL if not initialized yet 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/OKQIBWIODW2QOMQ7EUO7V32UPMS2J5Y7/> 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: Import dlmalloc 2.8.6
|
|
Commit Message
Simon Glass
Dec. 1, 2025, 5:04 p.m. UTC
From: Simon Glass <simon.glass@canonical.com> When malloc() was called before it was properly initialized (as would happen if when used before relocation to RAM) it returned random, non-NULL values, which called all kinds of difficult to debug subsequent errors. Make sure to return NULL when initialization was not done yet. Signed-off-by: Simon Glass <simon.glass@canonical.com> (cherry picked from commit 2740544881f652566756815dda4da0bcd946e9de) --- common/dlmalloc.c | 5 +++++ 1 file changed, 5 insertions(+)
diff --git a/common/dlmalloc.c b/common/dlmalloc.c index ff13a779211..baa9b500e10 100644 --- a/common/dlmalloc.c +++ b/common/dlmalloc.c @@ -4582,6 +4582,11 @@ static void* tmalloc_small(mstate m, size_t nb) { #if !ONLY_MSPACES void* dlmalloc(size_t bytes) { +#ifdef __UBOOT__ + /* Return NULL if not initialized yet */ + if (!mem_malloc_start && !mem_malloc_end) + return NULL; +#endif /* Basic algorithm: If a small request (< 256 bytes minus per-chunk overhead):