summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSam Protsenko <semen.protsenko@linaro.org>2025-01-11 21:42:11 -0600
committerTom Rini <trini@konsulko.com>2025-06-20 08:01:09 -0600
commit11319e0e2bbf7b3892658d45017cd80c41ad961b (patch)
tree9f6d7df07d0fb03e5b92965b33db21f18ad43ecb
parent4bbfd1c04277d83783266fae754b2227cbc5caae (diff)
bootstd: Fix memleak on errors in bootmeth_setup_iter_order()
Free memory allocated for 'order' (array of bootmeths) on error paths in bootmeth_setup_iter_order() function. Fixes: c627cfc14c08 ("bootstd: Allow scanning for global bootmeths separately") Fixes: 10d16faa436c ("bootstd: Detect empty bootmeth") Signed-off-by: Sam Protsenko <semen.protsenko@linaro.org> Reviewed-by: Simon Glass <sjg@chromium.org>
-rw-r--r--boot/bootmeth-uclass.c16
1 files changed, 12 insertions, 4 deletions
diff --git a/boot/bootmeth-uclass.c b/boot/bootmeth-uclass.c
index 014b7588e8d..cb84bb03447 100644
--- a/boot/bootmeth-uclass.c
+++ b/boot/bootmeth-uclass.c
@@ -135,8 +135,10 @@ int bootmeth_setup_iter_order(struct bootflow_iter *iter, bool include_global)
* We don't support skipping global bootmeths. Instead, the user
* should omit them from the ordering
*/
- if (!include_global)
- return log_msg_ret("glob", -EPERM);
+ if (!include_global) {
+ ret = log_msg_ret("glob", -EPERM);
+ goto err_order;
+ }
memcpy(order, std->bootmeth_order,
count * sizeof(struct bootmeth *));
@@ -190,8 +192,10 @@ int bootmeth_setup_iter_order(struct bootflow_iter *iter, bool include_global)
}
count = upto;
}
- if (!count)
- return log_msg_ret("count2", -ENOENT);
+ if (!count) {
+ ret = log_msg_ret("count2", -ENOENT);
+ goto err_order;
+ }
if (IS_ENABLED(CONFIG_BOOTMETH_GLOBAL) && include_global &&
iter->first_glob_method != -1 && iter->first_glob_method != count) {
@@ -202,6 +206,10 @@ int bootmeth_setup_iter_order(struct bootflow_iter *iter, bool include_global)
iter->num_methods = count;
return 0;
+
+err_order:
+ free(order);
+ return ret;
}
int bootmeth_set_order(const char *order_str)