From: Frieder Schrempf <[email protected]>
The RAUC bootmeth loads the boot script when booting, not when reading
the bootflow. If the boot fails, the bootflow keeps its private data and
can be booted again, for example with another 'bootflow boot'. Each
attempt then loads the script into a new buffer and adds another image
to the bootflow, but the previous buffer, image list entry and subdir
are never freed. 'bootstd images' lists one more copy of boot.scr after
every attempt.
Free what a previous attempt loaded before loading the script again,
in the same way as bootflow_free(). Also check the strdup() of the
subdir.
Fixes: 7e5c2c782fb9 ("bootstd: Add implementation for bootmeth rauc")
Assisted-by: LLM
Signed-off-by: Frieder Schrempf <[email protected]>
---
boot/bootmeth_rauc.c | 12 ++++++++++++
1 file changed, 12 insertions(+)
diff --git a/boot/bootmeth_rauc.c b/boot/bootmeth_rauc.c
index fc073aadd21..3bb9a2ace3d 100644
--- a/boot/bootmeth_rauc.c
+++ b/boot/bootmeth_rauc.c
@@ -285,6 +285,7 @@ static int distro_rauc_load_boot_script(struct bootflow
*bflow,
{
struct blk_desc *desc;
struct distro_rauc_priv *priv;
+ struct bootflow_img *img;
struct udevice *bootstd;
const char *const *prefixes;
int ret;
@@ -305,6 +306,15 @@ static int distro_rauc_load_boot_script(struct bootflow
*bflow,
if (!bflow->part)
return log_msg_ret("part", -ENOENT);
+ /* Drop the boot script of a previous, failed boot attempt */
+ free(bflow->buf);
+ bflow->buf = NULL;
+ free(bflow->subdir);
+ bflow->subdir = NULL;
+ alist_for_each(img, &bflow->images)
+ free(img->fname);
+ alist_empty(&bflow->images);
+
ret = bootmeth_setup_fs(bflow, desc);
if (ret)
return log_msg_ret("set", ret);
@@ -316,6 +326,8 @@ static int distro_rauc_load_boot_script(struct bootflow
*bflow,
prefixes[i], script_names[j],
bflow->dev->name, bflow->part);
bflow->subdir = strdup(prefixes[i]);
+ if (!bflow->subdir)
+ return log_msg_ret("buf", -ENOMEM);
}
}
}
--
2.56.0