From patchwork Sat Jan 10 20:28:37 2026 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Simon Glass X-Patchwork-Id: 1451 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=1768076986; bh=CF8Sf3nUHPPWtOtARNwP40iiMMAU8M0LgTGR7ISUfPA=; 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=PDPPtSNaXpNNPvKSobE6vEpDobxH7a9b1LPFxW+o4m7uC30rwaQsppiMUa2jlHL/Y /Wn1umCXrExpNdnN8Otz6wB2lq0s+KpE5G6nCTW7Cw8BIq/hdmqtlSB6JWWX7sW9SX bWwvPxAvhuCgcnWqC0MPGBuQkXhwggLe08XkG1aTupyarfyEcEfeuLGaHykp2rkzEa eHvMWcLek+rX/QJYLkR1YzA0epB1Jqn9q4cpJsRRS0hU8vZlFyIHVM2qPHym9+N3Q8 4j9Nu+MlkfmzLZdtcMdI1Pj86cEb5g50moCDyrDzIg5cQ7qDfCZAVzKbibhjSEqQ6+ 6BS+Ld5G0UOBQ== Received: from localhost (localhost [127.0.0.1]) by mail.u-boot.org (Postfix) with ESMTP id 8DA8569291 for ; Sat, 10 Jan 2026 13:29:46 -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 I6HJ0C9rDLC1 for ; Sat, 10 Jan 2026 13:29:46 -0700 (MST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=u-boot.org; s=default; t=1768076986; bh=CF8Sf3nUHPPWtOtARNwP40iiMMAU8M0LgTGR7ISUfPA=; 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=PDPPtSNaXpNNPvKSobE6vEpDobxH7a9b1LPFxW+o4m7uC30rwaQsppiMUa2jlHL/Y /Wn1umCXrExpNdnN8Otz6wB2lq0s+KpE5G6nCTW7Cw8BIq/hdmqtlSB6JWWX7sW9SX bWwvPxAvhuCgcnWqC0MPGBuQkXhwggLe08XkG1aTupyarfyEcEfeuLGaHykp2rkzEa eHvMWcLek+rX/QJYLkR1YzA0epB1Jqn9q4cpJsRRS0hU8vZlFyIHVM2qPHym9+N3Q8 4j9Nu+MlkfmzLZdtcMdI1Pj86cEb5g50moCDyrDzIg5cQ7qDfCZAVzKbibhjSEqQ6+ 6BS+Ld5G0UOBQ== Received: from mail.u-boot.org (localhost [127.0.0.1]) by mail.u-boot.org (Postfix) with ESMTP id 7BD3A69281 for ; Sat, 10 Jan 2026 13:29:46 -0700 (MST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=u-boot.org; s=default; t=1768076984; bh=wmFepeOcu8V2jmwvasn5OGY45Xys/tApu+COkSPYBLI=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=EQIyGfkkRqdzsH5Pp/1mjgFAtQAuqxLL/f+OIWTykZAwOXoPJEENmJpDjMmlfIOkN 8ppHGf0cyN2jJ3S7Vcs6o/KsciHaZoIV8fF7cWgLRsSEcHJ7qTNEx+lEhyLM/nwK5q Y3Ocz5h/VdSGDOsrOcK52aZX4vR0kB5tb/g5A3AmYUKfpNZcuYgA1/qAnCBSWMAV+U lTPAp34RONQwsyFjJJUOY1ROifSLf95aVVt+qY07xE4+jPg35xmfnSM/tAZsyYoXnD FGbUwtfGmFrW16lF3/tS08dYh4VPAqaQu+WM5+X4V2rsqxL9jvmFE/fWAncOuZ0utL j3Enp3YGYUd6A== Received: from localhost (localhost [127.0.0.1]) by mail.u-boot.org (Postfix) with ESMTP id 7C38769281; Sat, 10 Jan 2026 13:29:44 -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 1NykMFLMjoy9; Sat, 10 Jan 2026 13:29:44 -0700 (MST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=u-boot.org; s=default; t=1768076980; bh=jHBLx8LVwseYMVgofBq64jj7uitZNP8jf84jV0zZd5o=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=AkctMjbxXN7nQxqKTNN+RFsui54qh0McNQrE2t89mHkwMjWWoSSVs3EubvVSebvHH +jfkFbkAJ6Ix1VpiT8iqUULPuIV7lmNNd1gglAYxIj9uQ3gIUJu/mS/VEitH8sB+TV bdlp55gcpdnphAR4JOZ/7Y9DIZQEr++QBKYPUIfmGmQzpFJFEjGuiexaYEU5iMtmgz mCPByyd34hL+PpdNY0UmOKvpgJVmv6O0OxoL/4m5FL3tqC4wPmGaQ9Dl+h7tid4UWj cKq4AykRwxhWyZmrlkGrEgfiV1NW7/yvx9m6EL1XIt7XWWCJJQJgxFwSMOyE6RdSHJ Qk4dCp108yRUg== Received: from u-boot.org (unknown [73.34.74.121]) by mail.u-boot.org (Postfix) with ESMTPSA id C7BDF69186; Sat, 10 Jan 2026 13:29:39 -0700 (MST) From: Simon Glass To: U-Boot Concept Date: Sat, 10 Jan 2026 13:28:37 -0700 Message-ID: <20260110202906.187370-6-sjg@u-boot.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20260110202906.187370-1-sjg@u-boot.org> References: <20260110202906.187370-1-sjg@u-boot.org> MIME-Version: 1.0 Message-ID-Hash: 3HQ4PYEUTYPSMV56QMHF4QXNSEVMCL4A X-Message-ID-Hash: 3HQ4PYEUTYPSMV56QMHF4QXNSEVMCL4A 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 , Simon Glass , "Claude Opus 4 . 5" X-Mailman-Version: 3.3.10 Precedence: list Subject: [Concept] [PATCH 05/26] boot: pxe: Fix memory leak in parse_fdtoverlays() 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 parse_sliteral() call allocates a string for val, but it is never freed after parsing the overlay paths. Each path is duplicated by strndup/strdup, so the original string can be freed. Save the original pointer and free it on exit and error paths. Co-developed-by: Claude Opus 4.5 Signed-off-by: Simon Glass --- boot/pxe_parse.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/boot/pxe_parse.c b/boot/pxe_parse.c index e5af05d4120..f6b7887f603 100644 --- a/boot/pxe_parse.c +++ b/boot/pxe_parse.c @@ -317,12 +317,13 @@ static int parse_sliteral(char **c, char **dst) */ static int parse_fdtoverlays(char **c, struct alist *overlays) { - char *val; + char *val, *start; int err; err = parse_sliteral(c, &val); if (err < 0) return err; + start = val; while (*val) { struct pxe_fdtoverlay item; @@ -348,10 +349,13 @@ static int parse_fdtoverlays(char **c, struct alist *overlays) if (!item.path || !alist_add(overlays, item)) { free(item.path); + free(start); return -ENOMEM; } } + free(start); + return 1; }