[Concept,07/14] cros: Implement free_bootflow to fix memory leak

Message ID 20260322235719.1729267-8-sjg@u-boot.org
State New
Headers
Series bootstd: Infrastructure for multi-entry bootflow support |

Commit Message

Simon Glass March 22, 2026, 11:57 p.m. UTC
  From: Simon Glass <sjg@chromium.org>

The ChromiumOS bootmeth allocates an info_buf inside cros_priv but
bootflow_free() only calls free() on the priv struct itself, so the
buffer is never freed.

Implement free_bootflow() to free info_buf before the priv struct.

Signed-off-by: Simon Glass <sjg@chromium.org>
---

 boot/bootmeth_cros.c | 9 +++++++++
 1 file changed, 9 insertions(+)
  

Patch

diff --git a/boot/bootmeth_cros.c b/boot/bootmeth_cros.c
index f92e4437b27..a09194ca270 100644
--- a/boot/bootmeth_cros.c
+++ b/boot/bootmeth_cros.c
@@ -467,10 +467,19 @@  static int cros_bootmeth_bind(struct udevice *dev)
 	return 0;
 }
 
+static void cros_free_bootflow(struct udevice *dev, struct bootflow *bflow)
+{
+	struct cros_priv *priv = bflow->bootmeth_priv;
+
+	if (priv)
+		free(priv->info_buf);
+}
+
 static struct bootmeth_ops cros_bootmeth_ops = {
 	.check		= cros_check,
 	.read_bootflow	= cros_read_bootflow,
 	.read_file	= cros_read_file,
+	.free_bootflow	= cros_free_bootflow,
 	.boot		= cros_boot,
 #if CONFIG_IS_ENABLED(BOOTSTD_FULL)
 	.read_all	= cros_read_all,