diff options
author | Martin Schwan <m.schwan@phytec.de> | 2025-07-14 15:30:08 +0200 |
---|---|---|
committer | Tom Rini <trini@konsulko.com> | 2025-07-22 13:53:17 -0600 |
commit | a7d1214d2c9a38af3a9a1271dd8388068cba904c (patch) | |
tree | d72a0bcdd06fc181d28c62fb4d8a8ad8530eae0c | |
parent | 6bb0679377abb01a82db1ce69b5bf1d40aa02ace (diff) |
bootstd: rauc: Fix potential memory leak
Fix a potential memory leak, by checking the return value of realloc
first, before assigning it to the private list of slots.
Signed-off-by: Martin Schwan <m.schwan@phytec.de>
-rw-r--r-- | boot/bootmeth_rauc.c | 8 |
1 files changed, 6 insertions, 2 deletions
diff --git a/boot/bootmeth_rauc.c b/boot/bootmeth_rauc.c index fc60e6e355d..6abbd25704b 100644 --- a/boot/bootmeth_rauc.c +++ b/boot/bootmeth_rauc.c @@ -168,13 +168,17 @@ static int distro_rauc_read_bootflow(struct udevice *dev, struct bootflow *bflow (slot = strsep(&boot_order_copy, " ")); i++) { struct distro_rauc_slot *s; + struct distro_rauc_slot **new_slots; s = calloc(1, sizeof(struct distro_rauc_slot)); s->name = strdup(slot); s->boot_part = simple_strtoul(strsep(&parts, ","), NULL, 10); s->root_part = simple_strtoul(strsep(&parts, ","), NULL, 10); - priv->slots = realloc(priv->slots, (i + 1) * - sizeof(struct distro_rauc_slot)); + new_slots = realloc(priv->slots, (i + 1) * + sizeof(struct distro_rauc_slot)); + if (!new_slots) + return log_msg_ret("buf", -ENOMEM); + priv->slots = new_slots; priv->slots[i - 1] = s; priv->slots[i]->name = NULL; } |