From patchwork Sun Mar 22 23:57:07 2026 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Simon Glass X-Patchwork-Id: 2041 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=1774223874; bh=VUwPpRMerbjofasODyiw93ueUcCkcMul3quj9LKwV2A=; 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=wjHtzi/dTqTnsoJiLvDoB3cekBqLynRIJwnbQNGm/I6iD33V1K8ZVQQ9ci5BsYcQi uqnXoH503uj8NgUZjxbgzMTmbnjAN9WCoh+dxdfKci1iPciK/FyPV5I1UPgTmklO27 /UmMDPgGL9uJRjpeIXDS2O/J78C/G+pzJ2KO+D2r4kJ+JHadaFqbaGt5G77DYo14oC mHNjWkrW7n2dCio7k08QL1brZ+vt5+W4d1oG+A1e0ySPaaueYzQYzCzuJ/+P1M9A5u oV6mLFCie9UMcJPMkq3VVbekF05LFOUvBtfSLOs1dr07OxTY//XJbaJA+Yn+NF257H PxmUpB8C9SePw== Received: from localhost (localhost [127.0.0.1]) by mail.u-boot.org (Postfix) with ESMTP id AC7E06A1DA for ; Sun, 22 Mar 2026 17:57: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 PFaj98TWiED9 for ; Sun, 22 Mar 2026 17:57:54 -0600 (MDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=u-boot.org; s=default; t=1774223870; bh=VUwPpRMerbjofasODyiw93ueUcCkcMul3quj9LKwV2A=; 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=hy5TQYvKPr7noZ+a8EStPahgRqP2mecZzBUdbBdBC6s051MAIb9EAaFSuR5aY3fll PEuF9fDeQ8XRKdAkgp/Hp9ZkqGMcKRiWeafTcIhGzRsw6KYPnwiZJlbmZwuG45BGhB Kf0XtPkSzeYjQ82oR2uBKkenEZztKRMmd0rYBrmQxs5MKHvwzXE72rczf7MVuoFGqZ NQrJRWEz3z6p69IWVgOmN7faRy9SOX6FIXFahS79NyRVG+NUJb/T8xXaZuPg6XtD5z pmBhXJEad9QSWoeU+0nWmWPE/cm31ywhFvI3hhVw7uzh3GrlAQyn7t5eagvPMqpX26 YWlnV6g9jno9Q== Received: from mail.u-boot.org (localhost [127.0.0.1]) by mail.u-boot.org (Postfix) with ESMTP id 32A736A1E3 for ; Sun, 22 Mar 2026 17:57:50 -0600 (MDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=u-boot.org; s=default; t=1774223864; bh=SSibNOUF4kD30Eog6DicrqgvURha5QY5bKKyAu0b/zs=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=kfFFlc1O22TZvuDaLP54V2ABs6TB7IxDu5mFZwWnWt/mBo/kXwk48p/9CeKsb5P/Q a6eouw7YYX/gsqXj4hDu8d3PzXKQzvjWNWtJ7TM2LRivhQduA1FOKlF+wXIDVv+MTs m6uRlQHTlHDiNRI0j5QsHaBn5m5XsN2cCB6h+FWTA5HO2ZboicmXg5nnaTpfMjbV6A xylZLEokUB776wuLRC+hpjhEud0QtvAXjus469AmsuczUEGXc7W9nGrzZLoXrUUTqt fp2D2ikWLDgfIKb7mgaya+kBgLexB6a1/ema1zzP3SBTOLeM8Z7xHUZ/pu94SJY5gx QlV/Lad2y2krQ== Received: from localhost (localhost [127.0.0.1]) by mail.u-boot.org (Postfix) with ESMTP id 58A436A1D7; Sun, 22 Mar 2026 17:57: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 gx9n_n37jM9h; Sun, 22 Mar 2026 17:57:44 -0600 (MDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=u-boot.org; s=default; t=1774223863; bh=Qy75oG+tgo5dWTGApXeSDdzKQUBcn4mg0Ha4m71qRvo=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=woHOBEJ+jYN/bcD54+vQuJHvIKO0hNQ8ocTYTJ0u/6mp+loKV4yh6LCplp0sedh1v m8JaKHdyE4RkFurMtU7BTDDqT8PsMa6NSZkmARquaqhS3vZtKamJiCRuHh4/dJKA90 xUFsIc6g4PI22lpwzLniojHDsG0lfVPrOgeqGLnU7+xbNEZ3BOYmi5JYs7YOoMFCsL 32rclnzOh+BvjS99ZBhOVU26ngfP0gkD2whynqXi7v3JjZa8FluzEqpl5a5CtIfwkF 5/yDlW9pktJEV4YTd7G9tlVPM5nkpbtVpH1s4uaMmsssvwy4zV+5WOCZ62okB7Xo+v pOcEz5z7wEXpA== Received: from u-boot.org (unknown [73.34.74.121]) by mail.u-boot.org (Postfix) with ESMTPSA id 6F3B46A1DD; Sun, 22 Mar 2026 17:57:43 -0600 (MDT) From: Simon Glass To: U-Boot Concept Date: Sun, 22 Mar 2026 17:57:07 -0600 Message-ID: <20260322235719.1729267-10-sjg@u-boot.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20260322235719.1729267-1-sjg@u-boot.org> References: <20260322235719.1729267-1-sjg@u-boot.org> MIME-Version: 1.0 Message-ID-Hash: 5UYHI5WNCDE6JDAV37CUJJSSKOYL4XYR X-Message-ID-Hash: 5UYHI5WNCDE6JDAV37CUJJSSKOYL4XYR 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 09/14] rauc: Implement free_bootflow to fix memory leak 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 RAUC bootmeth allocates a slots array with internal name strings inside distro_rauc_priv. A plain free() on the priv struct leaks all of these. The driver already has distro_rauc_priv_free() for proper cleanup but it is not called from bootflow_free(). Implement free_bootflow() to use the existing cleanup function. Since bootmeth_free_bootflow() now handles freeing the priv struct itself, remove that from distro_rauc_priv_free() and add explicit free() + NULL at the two call sites in read_bootflow and boot which do their own cleanup. Signed-off-by: Simon Glass --- boot/bootmeth_rauc.c | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/boot/bootmeth_rauc.c b/boot/bootmeth_rauc.c index a81178db574..53d8dd7836f 100644 --- a/boot/bootmeth_rauc.c +++ b/boot/bootmeth_rauc.c @@ -63,7 +63,6 @@ static void distro_rauc_priv_free(struct distro_rauc_priv *priv) free(priv->slots[i]); } free(priv->slots); - free(priv); } static struct distro_rauc_slot *get_slot(struct distro_rauc_priv *priv, @@ -202,6 +201,8 @@ static int distro_rauc_read_bootflow(struct udevice *dev, struct bootflow *bflow ret = distro_rauc_scan_parts(bflow); if (ret < 0) { distro_rauc_priv_free(priv); + free(priv); + bflow->bootmeth_priv = NULL; free(boot_order_copy); return ret; } @@ -412,6 +413,8 @@ static int distro_rauc_boot(struct udevice *dev, struct bootflow *bflow) return log_msg_ret("boot", ret); distro_rauc_priv_free(priv); + free(priv); + bflow->bootmeth_priv = NULL; return 0; } @@ -426,10 +429,18 @@ static int distro_rauc_bootmeth_bind(struct udevice *dev) return 0; } +static void distro_rauc_free_bootflow(struct udevice *dev, + struct bootflow *bflow) +{ + if (bflow->bootmeth_priv) + distro_rauc_priv_free(bflow->bootmeth_priv); +} + static struct bootmeth_ops distro_rauc_bootmeth_ops = { .check = distro_rauc_check, .read_bootflow = distro_rauc_read_bootflow, .read_file = distro_rauc_read_file, + .free_bootflow = distro_rauc_free_bootflow, .boot = distro_rauc_boot, };